VMware Cloud Community
Jimleslie1977
Contributor
Contributor

Use PowerCLI to amend NTP time setting on ESX Host

Hi and thanks for any assistance.

We have roughly 80 ESXi hosts running a mixture of 6.7 and 7.03.  I would like to use Powercli to access each one, remove any currently configure NTP setting and replace with a new one.  I have no idea where to start with this one, could somebody please help?

0 Kudos
3 Replies
LucD
Leadership
Leadership

You can use the Remove-VMHostNTPServer and Add-VMHostNtpServer cmdlets.
Something like this perhaps

$new = '192.168.1.1','192.168.1.2'

Get-VMHost | ForEach-Object -Process {
    $current = Get-VMHostNtpServer -VMHost $_
    Remove-VMHostNtpServer -VMHost $_ Get-VMHostNtpServer $current -Confirm:$false
    Add-VMHostNtpServer -VMHost $_ -NtpServer $new -Confirm:$false
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Jimleslie1977
Contributor
Contributor

Thanks, Could this be addapted to refrence a list of ESXhost names from a csv file?

0 Kudos
LucD
Leadership
Leadership

Assuming your CSV has a column, named Name, with the VMHost names, you could do

$new = '192.168.1.1','192.168.1.2'

Import-Csv -Path .\names.csv -UseCulture |
ForEach-Object -Process {
    $esx = Get-VMHost $_.Name 
    $current = Get-VMHostNtpServer -VMHost $esx
    Remove-VMHostNtpServer -VMHost $esx Get-VMHostNtpServer $current -Confirm:$false
    Add-VMHostNtpServer -VMHost $esx -NtpServer $new -Confirm:$false
}

 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos