ESX(i) NTP Server settings: PowerCLI

I read a great post by Roger Lund today that discussed timekeeping in VMware virtual machines. That got me thinking, “How would this be handled with PowerCLI?” A blog post was born. ๐Ÿ™‚

The first thing that I did was to check the NTP server settings on all of my VMware servers.

$vmhosts = Get-VMHost
$details = @()
foreach ($vmhost in $vmhosts) {
	$detail = "" | select Name,NTPServer
	$detail.Name = $vmhost.Name
	$detail.NTPServer = Get-VMHostNtpServer $vmhost
	$details += $detail

Pretty straightforward. Retrieve all of the VMhosts within vCenter, create an array to hold the results, then begin cycling thru all of the hosts and add their hostnames and NTP server settings into the results array. The results come out looking like this:

Name                        NTPServer
----                        ---------   

So, what do you do if you want to change the host that is missing the NTP server settings?

Get-VMHost -Name | Add-VmHostNtpServer -NtpServer ""
Get-VMHostService | Where-Object {$_.key -eq "ntpd"} | Restart-VMHostService -Confirm:$false 

There you have it. Isn’t PowerCLI great? ๐Ÿ™‚


  1. Happy Birthday to your sweet little girl. That is so cool you get to pick your own yellos flowers when your out and about. It's only leaves on this side of the world. Loved it all!

  2. July 3, 2008 – 5:17 am Great article, Matt! I am tempeted print it out and give it to all those clients that argue with me that what they currently have is just fine. You made fantastic points very fast and in easy-to-understand terms for businesses.

  3. Ooh! I liked their banter too. I loved it when Stefan had that sweet voice and told Klaus he could pick who they’d kill. Hilarious. Yeah, that would have been more believable; if it was just a shy smile. Though, I can’t help but hope that Delena would just happen already. Lol. I’m sure there’s fanfiction already for that. Haha! That would make a could title “Switching Salvatores” . . . You should remember, Katherine is ALWAYS up to something. P.S. Don’t forget your Damon hug

  4. Thanks Karen. I love highlighters but I also love peachy blushes That’s a tough one and I definitely shouldn’t get both. Btw, have you seen the new Chanel highlighting powder? It’s sooo gorgeous!!!

  5. you should add:
    if empty (or )
    add-vmhostntp ….

  6. in PowerCLI 4.1 i get
    Get-VMHostNtpServer : 11/18/2010 8:59:45 PM Get-VMHostNtpServer Index was outside the bounds of the array.
    At line:4 char:40
    + $detail.NTPServer = Get-VMHostNtpServer <<<< -vmhost $vmhost
    + CategoryInfo : NotSpecified: (:) [Get-VMHostNtpServer], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.GetVMHostNtpServer

    any ideas what im doing wrong?

Speak Your Mind