Following on my previous post I wanted to set NTP servers for my ESX servers and also start the service & allow firewall exceptions. Here’s what I did –
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# modify this with your vCenter server name $vcenter = "mycenterserver" $vcuser = Get-Credential Connect-VIServer -Server $vcenter -Credential $vcuser # remove the ?{ } clause if you want to target all hosts # I want to only target hosts with "xyz" in their name as I have different NTP servers per location $vmhosts = Get-VMHost | ?{ $_.Name -match "xyz" } | { $vmhost = $_.Name Write-Host -ForegroundColor Yellow "Looking at $vmhost " Write-Host -ForegroundColor Yellow "Removing all existing NTP server entries" Get-VMHostNtpServer -VMHost $vmhost | %{ Remove-VMHostNtpServer -VMHost $vmhost -NtpServer $_ -Confirm:$false} Write-Host -ForegroundColor Yellow "Adding new NTP server entries" Add-VMHostNtpServer -VMHost $vmhost -NtpServer "172.x.x.x" Add-VMHostNtpServer -VMHost $vmhost -NtpServer "192.x.x.x" Write-Host -ForegroundColor Yellow "Making firewall exceptions, starting the service, setting it to start automatically" Get-VMHostFirewallException -VMHost $vmhost| where {$_.Name -eq "NTP client"} | Set-VMHostFirewallException -Enabled:$true Get-VmHostService -VMHost $vmhost | Where-Object {$_.key -eq "ntpd"} | Start-VMHostService Get-VmHostService -VMHost $vmhost | Where-Object {$_.key -eq "ntpd"} | Set-VMHostService -policy "automatic" } |