ESXi NTP PowerShell Script

I wanted a quick way to configure NTP settings on a number of VMware ESXi hosts across two datacenters. Hosts in site A should point to the NTP source locally primarily and to site B NTP as a secondary source and vice versa for hosts in site B. The following isn’t perfect and a lot could be done to improve it but considering it’s just a quick way of achieving a task I’m not too bothered.

  • I check to see if the VMware PowerCLI addon is installed in the default location -we could improve this test by checking the registry or another value
  • We define a few variables either statically or by interacting at the prompt with our user
  • Load the PowerCLI plugin, connect to vCenter and start configuring hosts
    • As the hosts in question all follow a specific naming convention the easiest thing to do was just say ‘if my hostname is like x then do this otherwise it must be of type y so do this instead’
  • Once we’ve configured the settings we make sure the service is allowed on the ESXi firewall and that it is set to run automatically

Plenty of ways this could be enhanced but then again we also have tools like host profiles and other techniques to ensure consistent settings across our infrastructure. When you’re just spinning up labs or environments that don’t (license wise) support some of the more advanced stuff then it’s useful to have a few scripts to speed things along.

Note – The IP addresses and hostname structure have been amended to provide examples, they aren’t from my production environment.



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.