I recently started reinstalling all my ESX hosts, so I wrote up a short script that is reconfiguring all hosts and sets the NTP configuration according to my wish:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
param( [string] $vcenter, [string] $ntpserver1, [string] $ntpserver2 ) # Add the VI-Snapin if it isn't loaded already if ( (Get-PSSnapin -Name "VMware.VimAutomation.Core" -ErrorAction SilentlyContinue) -eq $null ) { Add-PSSnapin -Name "VMware.VimAutomation.Core" } If ( !($vcenter) -or !($ntpserver1) -or !($ntpserver2) ) { Write-Host `n "vcenter-ntp-reconfigure: <vcenter-server> <ntpserver1> <ntpserver2>" `n Write-Host "This script clears the NTP servers currently configured and" `n Write-Hsot "adds the ones supplied on the command line." `n Write-Host " <vcenter-server> - DNS name of your vCenter server." `n Write-Host " <ntpserver1> - NTP server #1" `n Write-Host " <ntpserver2> - NTP server #2" `n exit 1 } Connect-VIServer -Server $vcenter foreach ($esxhost in Get-VMHost) { Get-VMHost $esxhost | Remove-VMHostNtpServer -Confirm:$false -NtpServer (Get-VMHost $esxhost | ` Get-VMHostNtpServer) Get-VMHost $esxhost | Add-VMHostNtpServer -NtpServer $ntpserver1 Get-VMHost $esxhost | Add-VMHostNtpServer -NtpServer $ntpserver2 } Disconnect-VIServer -server $vcenter -Confirm:$false |
As you can see, the script takes the vCenter hostname and two NTP servers and basically applies it to each host in your vCenter environment.