PowerCLI: Reconfiguring NTP Servers on ESX Hosts

Just lately I’ve been creating a lot of 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. I didn’t fancy spending all morning manually changing them, so I set to work in creating a PowerCLI script to do the business. Here is the result.

$Cluster = "<cluster name>"
$Hosts = Get-Cluster $Cluster | Get-VMHost
ForEach ($Host in $Hosts)
{
Remove-VmHostNtpServer -NtpServer "<old ntp server>" -VMHost $Host | Out-Null
Add-VmHostNtpServer -NtpServer "<new ntp server>" -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"
}

Related posts:

  1. PowerCLI: A Simple VM Backup Script
  2. Adding Virtual PortGroups to all ESX Hosts in a Cluster
  3. Adding a Virtual PortGroup to all Hosts
  4. Using vMA As Your ESXi Syslog Server
  5. VMware ESXi 4 Log Files
  • HJ
    hi
    Great, just what i needed!
    If i have more than one cluster, how would the script need to be changed?
    (say i added all clusters in a file clusters.txt)

    HJ
blog comments powered by Disqus
Get Adobe Flash playerPlugin by wpburn.com wordpress themes