Options

Bulk configure NPT Servers

azjagazjag Member Posts: 579 ■■■■■■■□□□
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 192.168.1.1
Get-VMHost | Add-VMHostNtpServer 192.162.1.2
Get-VMHost | Remove-VMHostNtpServer -NtpServer 192.168.1.3
Get-VMHost | Remove-VMHostNtpServer -NtpServer 192.168.1.4
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 192.168.1.1 and 192.168.2.1 as examples to apply as NTP servers, and 192.168.1.3 and 192.168.1.4 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)

Comments

Sign In or Register to comment.