Tuesday, August 30, 2016

Configuring NTP server using PowerCLI

Below scripts executes against all the ESXi hosts under the vCenter Server. 

1) Remove old NTP server settings & add new NTP server settings:

connect-viserver vcenterservername
foreach($vmhost in get-vmhost){
#stop ntpd service
$vmhost|Get-VMHostService |?{$_.key -eq 'ntpd'}|Stop-VMHostService -Confirm:$false
#remove ntpservers 
$vmhost|Remove-VMHostNtpServer -NtpServer $oldntpservers -Confirm:$false
#add new ntpservers
$vmhost|Add-VmHostNtpServer -NtpServer $newntpservers
#start ntpd service
$vmhost|Get-VMHostService |?{$_.key -eq 'ntpd'}|Start-VMHostService

2) Add new NTP server settings:

Connect-VIServer vcenterservername
Get-VMHost | Add-VMHostNtpServer
Get-VMHost | Add-VMHostNtpServer
Get-VMHost | Get-VMHostFirewallException | where {$_.Name -eq "NTP client"} | Set-VMHostFirewallException -Enabled:$true
Get-VMHost | Get-VmHostService | Where-Object {$_.key -eq "ntpd"} | Start-VMHostService

Get-VMhost | Get-VmHostService | Where-Object {$_.key -eq "ntpd"} | Set-VMHostService -policy "automatic"

No comments:

Post a Comment