Modify NTP servers on ESXi hosts

From VVCWiki
Jump to navigationJump to search
$hosts = get-vmhost
foreach ($server in $hosts)
{
  write-host $server
  $oldntps = Get-VMHostNtpServer -VMHost $server
  foreach ($ntp in $oldntps)
  {
    Remove-VmHostNtpServer -NtpServer $ntp -VMHost $server -Confirm:$false
  }
  Add-VmHostNtpServer -NtpServer "10.70.32.3" -VMHost $server
  Add-VmHostNtpServer -NtpServer "10.70.10.3" -VMHost $server
  Add-VmHostNtpServer -NtpServer "192.168.254.107" -VMHost $server
  Get-VmHostService -VMHost $server | Where-Object {$_.key -eq "ntpd"} | Restart-VMHostService -Confirm:$false
}