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

11 thoughts on “PowerCLI: Do you have the time ?”

  1. Hi, It was great help since I am not familiar with lot of PowerCLI. I am newb into this world. Also I don’t get .csv file on my C:\. when I added it was ended >> just stays their and I did’n’t find any file generated.

  2. hi Alan..if you can help advise how can I get the cluster name…host name and the NTP server and its status in one output…that would be great.

  3. Thanks for this Alan, now just looking for a way to remove a entry when the NTP list contains the wrong server or I wish to change NTP servers?.

  4. Hi Alan,
    Thank you so much for your scripts.
    Is that possible create a script for limit the number of snapshots to the list of the servers from a text file.
    Actually I am also looking for the script for “Enable Memory/vCPU Hotplug if supported by OS”.
    Highly appreciated your help on this.

    Thanks
    Jasti

  5. 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 🙂

  6. 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

Leave a Reply