Modify NTP servers on ESXi hosts

From VVCWiki
Revision as of 15:50, 29 November 2013 by Vvc (talk | contribs) (Created page with "<source lang="powershell"> $hosts = get-vmhost foreach ($server in $hosts) { write-host $server $oldntps = Get-VMHostNtpServer -VMHost $server foreach ($ntp in $oldntps)...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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
}