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. I am a librarian. So many people asked to borrow Dan Brown’s Da Vinci Code that I eventually read it myself to see what the fuss was about. Absolute junk! Maybe suitable for a 10 year old child but not adult reading. I have not wasted time reading any other books by Dan Brown. Having read the reviews posted here, I note that other people are also (finally) beginning to realise that this author has no talent and produces work of insultingly low quality.

  2. Some of my most well-received, commented on posts, flash fiction and poems are the ones that come straight from the soul, the ones that have me second-guess myself and questions if I should hit “publish” or bury them…Estrella Azul recently posted..

  3. 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!

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

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

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

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

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