Sorry for the lack of updates recently, I have been on vacation.  I thought I would ease myself back in with a quick one-liner.

We had an issue on one of our esx hosts today and when I went to check the logs I noticed the time was out, on further checking the server the NTP service had stopped.

I wrote a quick one liner to double check all our Hosts were using the same NTP Server and that the service was started:

Get-VMHost |Sort Name|Select Name, @{N=NTPServer;E={$_ |Get-VMHostNtpServer}}, @{N=ServiceRunning;E={(Get-VmHostService -VMHost $_ |Where-Object {$_.key-eq ntpd}).Running}}

This will give you a nice table letting you know the state of your hosts time, if you do happen to have a host with an incorrect NTP server then you can set it like this:

Add-VMHostNtpServer -VMHost MYHost -NtpServer ntp.mydomain.com

Or if one of the services has stopped you can start it again with the following:

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

Example output from my one-liner:

Name NTPServer ServiceRunning
testesx01.mydomain.com ntp.mydomain.com TRUE
testesx02.mydomain.com ntp.mydomain.com FALSE