Month: July 2019

Leave a reply

Checking ESXi NTP

So i just happen to check the time on one of my ESXi hosts, and noticed that the time was way off, by like hours. I checked the NTP service on the host, and it was not running. So updated and stated to check the other hosts. However, I didn’t feel like logging into each one. So I found a few one liners that helped me check all the hosts in my environment, and updated where necessary.

First, connect to the appropriate vcenter
then run the following to get the time and service status on all hosts on that vCenter

Get-VMHost | Sort-Object Name |  Select Name, @{N=";NTPServer";;E={$_ |Get-VMHostNtpServer}}, Timezone, @{N=";CurrentTime";;E={(Get-View $_.ExtensionData.ConfigManager.DateTimeSystem) | Foreach {$_.QueryDateTime().ToLocalTime()}}}, @{N=";ServiceRunning";;E={(Get-VmHostService -VMHost $_ | Where-Object {$_.key -eq "ntpd";}).Running}} ` | Format-Table -AutoSize 

If you need to update your ntp server
First, remove the old NTP Server

Remove-VMHostNTPSserver -NTPServer <NTP Server> -vmhost (Get-VMHost) -confirm

Second, add the new one

Get-VMHost | Add-VMHostNtpServer -NtpServer

If you need start and stop the NTP Service and set to automatic

Get-VMHost| Get-VMHostService| Where-Object{$_.key -eq"ntpd"} | Start-VMHostServiceGet-VMHost

Get-VMHostService| Where-Object{$_.key -eq"ntpd"} | Set-VMHostService-policy "automatic"

That should get the host back on the same time

On a side note, I did this all with PowerShell Core on Ubuntu, with the VMWare Core powershell modules loaded. I noticed, that if you use Sort, rather than Sort-Object pwsh does not recognize it.

%d bloggers like this: