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.
https://paulsbestscriptlets.com/2018/07/05/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