Thursday, March 11, 2010

PowerCLI: Reconfiguring NTP Servers on ESX Hosts

I’ve been creating a PowerCLI scripts to help configure various aspects of out ESX environment. We’ve just implemented a new NTP Server to our network. So I was given the job to update all of our ESX Hosts.

$Cluster = "XXX"
$Hosts = Get-Cluster $Cluster Get-VMHost
ForEach ($Host in $Hosts)
{
Remove-VmHostNtpServer -NtpServer "" -VMHost $Host Out-Null
Add-VmHostNtpServer -NtpServer "" -VMHost $Host Out-Null
Get-VmHostService -VMHost $Host Where-Object {$_.key -eq "ntpd"} Restart-VMHostService -Confirm:$false Out-Null
write "NTP Server was changed on $Host"
}