Here is a script that will query vSphere for all of your hosts, set the new NTP FQDN and restart the NTP service. If you only want a subset of the hosts in vSphere, you can use the –location switch with the Get-VMHost command. You’ll also need Power CLI installed to get the vSphere commands.
## Verify $NTPServer is correct
## Change credentials to your own account
## Written by Brady Randolph of RBA Consulting.
$creds = Get-Credential -Credential "domain\user"
Connect-VIServer -Server "vSphere Server Name" -Credential $creds
$NTPServer = "NTP FQDN"
$hosts = Get-VMHost
ForEach ($vmhost in $Hosts){
$currentNTP = Get-VMHostNtpServer -VMHost $vmhost
if ($currentNTP -ne $NTPServer) {
Remove-VmHostNtpServer -NtpServer $currentNTP -VMHost $vmhost -ErrorAction Continue | Out-Null
Add-VmHostNtpServer -NtpServer $NTPServer -VMHost $vmhost | Out-Null
Get-VmHostService -VMHost $vmhost | Where-Object {$_.key -eq "ntpd"} | Restart-VMHostService -Confirm:$false | Out-Null
write "NTP Server was changed on $vmhost"}
else { "NTP Server was correct on $vmhost"}
}
