Bulk configure NPT Servers

azjagazjag Posts: 579Member
Hello all,

I wanted to share a bit of code with you today. My company is actively migrating from 2003 AD (I know) to 2012 AD and we needed to update the NTP servers on all of our hosts. After some time googling and trial and error I was able to add the new servers, remove the old servers, set the firewall exception service, and enable the service. I used the latest version of PowerCLI for this.
Connect-VIServer vCenterServerHostName
Get-VMHost | Add-VMHostNtpServer
Get-VMHost | Add-VMHostNtpServer
Get-VMHost | Remove-VMHostNtpServer -NtpServer
Get-VMHost | Remove-VMHostNtpServer -NtpServer
Get-VMHost | Get-VMHostFirewallException | where {$_.Name -eq "NTP client"} | Set-VMHostFirewallException -Enabled:$true
Get-VMHost | Get-VmHostService | Where-Object {$_.key -eq "ntpd"} | Start-VMHostService
Get-VMhost | Get-VmHostService | Where-Object {$_.key -eq "ntpd"} | Set-VMHostService -policy "automatic"

Before running, be sure to replace the vCenterServerHostName with your vCenter Server IP or FQDN.
I used and as examples to apply as NTP servers, and and as examples to remove NTP servers. Please change these fields to reflect your environment.

The commands execute against all your vSphere hosts under the vCenter Server you are connecting to. If you want to configure a single host, use Get-VMHost hostname where hostname is the name of your ESXi box inside vCenter Server.

Credit where credit is due
Currently Studying:
VMware Certified Advanced Professional 5 – Data Center Administration (VCAP5-DCA) (Passed)
VMware Certified Advanced Professional 5 – Data Center Design (VCAP5-DCD)


  • Rick9Rick9 Posts: 27Member ■□□□□□□□□□
    Thank you, that's quite interesting!
Sign In or Register to comment.