---
title: "Use PowerCli to modify/update NTP servers settings on VMware Hypervisors"
canonical: "https://www.virtcloudrocks.com/space/VSPHTECH01/852152/Use%20PowerCli%20to%20modify%2Fupdate%20NTP%20servers%20settings%20on%20VMware%20Hypervisors"
format: markdown
---
Below technical article provide some useful powercli commands/scripts that can be used to modify (create/delete/update) NTP server settings to a set of VMware ESXi hosts.

Those can be quite useful in case that you have a lot of hypervisors that need to be updated.

# Restart NTP services to multiple hypervisors

| Step | Task |
| --- | --- |
| 1 | Open VMware PowerCLI and connect to the vCenter or vCenters to which the hosts exist,<br>```powershell
Connect-VIServer -Server <IP or FQDN of the server> -Username <username> -Password <password of the user>
``` |
| 2 | Create a new powershell script file and copy/paste below code,<br>```powershell
foreach($vmhost in get-vmhost){
 #restart ntpd service
 $vmhost|Get-VMHostService |?{$_.key -eq 'ntpd'}| Restart-VMHostService -Confirm:$false
}
```<br>The code runs a loop on each of the hosts, and restart the NTP service, (ntpd) |
| 3 | Run the newly created powercli script. |


# Update NTP servers to multiple hypervisors

Below Powercli script can be used to update the already configured NTP servers to multiple ESXi hypervisors,

| Step | Task |
| --- | --- |
| 1 | Open VMware PowerCLI and connect to the vCenter or vCenters to which the hosts exist,<br>```powershell
Connect-VIServer -Server <IP or FQDN of the server> -Username <username> -Password <password of the user>
``` |
| 2 | Create a new powershell script file and copy/paste below code,<br>```powershell
# variable used to store the old NTP servers configured
$oldntpservers='10.10.10.5','10.10.10.6'


# variable used to store the new NTP servers that will be configured
$newntpservers='10.200.100.5','10.200.100.6'


# perform a loop on each of the hypervisors
foreach($vmhost in get-vmhost){
	# initially stop the ntpd service
	$vmhost|Get-VMHostService |?{$_.key -eq 'ntpd'}|Stop-VMHostService -Confirm:$false

	# remove old NTP servers
	$vmhost|Remove-VMHostNtpServer -NtpServer $oldntpservers -Confirm:$false

	#add the new NTP servers
	$vmhost|Add-VmHostNtpServer -NtpServer $newntpservers


	# Start the ntpd service
	$vmhost|Get-VMHostService |?{$_.key -eq 'ntpd'}|Start-VMHostService
}
``` |
| 3 | Run the powercli script and verify that all the NTP servers have been updated to the ESXi hosts successfully. |


---

<u>**External References**</u>

How to use PowerCli to update the NTP Servers on all VMHosts at once.

[http://notesofascripter.com/2015/09/22/how-to-use-powercli-to-update-the-ntp-servers-on-all-vmhosts-at-once/](http://notesofascripter.com/2015/09/22/how-to-use-powercli-to-update-the-ntp-servers-on-all-vmhosts-at-once/)