Update ESXi hosts time with PowerCLI

Time synchronization is always very critical on ESXi and normally setting up the NTP servers is enough pretty much for any environment.
But when it comes to nested environments I normally suspend the vESXi as a result the time freeze. Now, after the vESXi is resumed you need to fix the time manually using the vSphere Client and this isn’t a big deal when you’re dealing with 1 or 2 hosts but when you start having a big nested environment (say 6 vESXi) it becomes annoying.

Solution? Automation of course 🙂 and what’s best than PowerCLI? Here’s the script that takes the time from the computer you’re running the script from and updates all the vSphere hosts within the vCenter Server location specified by you. Nice ah ? 🙂


Connect-VIServer YOURVC -SaveCredentials

Get-VMHost -Location YOURFOLDER-OR-CLUSTER | Where-Object {
$MyTime = Get-Date
$MyHost = $_ | %{ Get-View $_.ExtensionData.ConfigManager.DateTimeSystem }
$MyHost.UpdateDateTime((Get-Date($MyTime.ToUniversalTime()) -format u))
}

Disconnect-VIServer YOURVC -Confirm:$false

Leave a Comment

Your email address will not be published.

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