Skip to content

Set NTP on all VMs ESXi

More and more we see NTP of VMs is getting overlooked. Now we have COVID-19 Infra and System admins need to have a NTP strategy that is robust and does not impact production.

Here is a powercli method to set ntp on all VMs to get from ESXi hosts.

In this blog I advise the prerequisite step of how to set NTP on ESXi.

NTP check with Powercli

Save file as TimeSync.ps1Run from powercli. 
.\TimeSync.ps1

Step 1. 
Create the temp folder on your Windows machine and generate a CSV for the VMs in vCenter.   
Get-View -ViewType virtualmachine | Select name,@{N=’ToolsConfigInfo’;E={$_.Config.Tools.syncTimeWithHost } } | Export-Csv  “c:\temp\dr\TimeSyncStatus.csv” -NoTypeInformation
Step 2 
Create the powercli script. 

Copy all text below this line
 – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Import-Csv c:\temp\TimeSyncStatus.csv | foreach {     $strNewVMName = $_.Name        #Update VMtools without reboot $vm = $strNewVMName$vmtest = Get-vm $vm | get-view$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo$vmConfigSpec.Tools.syncTimeWithHost = $true$vmtest.reconfigVM($vmConfigSpec)
}

  – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – -Copy all text above this line
Step 3
Save file as TimeSync.ps1Run from powercli. 
.\TimeSync.ps1

Categories

Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: