Just lately I’ve been creating a lot of PowerCLI scripts to help configure various aspects of out ESX environment. We’ve just implemented a new NTP Server to our network. So I was given the job to update all of our ESX Hosts. I didn’t fancy spending all morning manually changing them, so I set to work in creating a PowerCLI script to do the business. Here is the result.
$Cluster = "<cluster name>" $Hosts = Get-Cluster $Cluster | Get-VMHost ForEach ($Host in $Hosts) { Remove-VmHostNtpServer -NtpServer "<old ntp server>" -VMHost $Host | Out-Null Add-VmHostNtpServer -NtpServer "<new ntp server>" -VMHost $Host | Out-Null Get-VmHostService -VMHost $Host | Where-Object {$_.key -eq "ntpd"} | Restart-VMHostService -Confirm:$false | Out-Null write "NTP Server was changed on $Host" }
Another VMworld is upon us!!! Sadly, it's only virtual again this year. However, that does…
As part of my recent move to Google, I'm working on quickly getting up to…
I am delighted to announce the next chapter in my career. Today is my first…
In episode thirteen of The VCDX Podcast, I am joined by two special guests who…
In my recent ‘Getting started with Oracle Cloud VMware Solution (OVCS)’ post; Getting Started With…
In my recent ‘Getting started with Oracle Cloud VMware Solution (OVCS)’ post; Getting Started With…
View Comments
hi
Great, just what i needed!
If i have more than one cluster, how would the script need to be changed?
(say i added all clusters in a file clusters.txt)
HJ
get rid of the $cluster variable and set your $hosts variable to the following
$hosts = get-vmhost
we have had multiple techs over the years use different values for "old ntp server". is there a command to use to remove whatever is there ?
Thanks, Claud
Hi Claud, you can probably use the Remove-VMHostNtpServer Cmdlet - https://www.vmware.com/support/developer/PowerCLI/PowerCLI41U1/html/Remove-VMHostNtpServer.html