PowerCLI: Do you have the time ?
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 |







about 7 months ago
Very useful Alan, thanks – I can’t think of a reason why you wouldn’t have NTP enabled – is there a way of taking these results and passing any failures to the start up script? I would think this would then be something that would run in a morning check script to keep the servers up to speed ..
Matt
about 7 months ago
Thats the reason I wrote this, I have added it to the next version of my daily report which I will hopefully be adding to my blog next week some time
about 6 months ago
Excellent script. Many thanks!