Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting NTP server on Windows machine using PowerShell

Tags:

powershell

We want to use Windows PowerShell to set an particular NTP server on Windows 7 workstations that are not attached to a domain. The goal is to have a number of scripts run to standardize/speed up/simplify the initial setup of non-domain workstations.

We have tried:

Push-Location
Set-Location HKLM:\SYSTEM\CurrentControlSet\services\W32Time\Parameters
Set-ItemProperty . NtpServer "ca.pool.ntp.org"
Pop-Location

And this script:

w32tm /config /manualpeerlist:ca.pool.ntp.org /syncfromflags:manual /update
Stop-Service w32time
Start-Service w32time

After running both scripts (with admin priv), we check the Registry and find NtpServer at: HKLM:\SYSTEM\CurrentControlSet\services\W32Time\Parameters has been updated to "ca.pool.ntp.org" but looking in Control Panel > Date and Time we find the old NTP server is still listed -- even if the computer is restarted.

this is the code which was developed from Graham Gold's response below and works:

Push-Location
Set-Location HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\DateTime\Servers
Set-ItemProperty . 0 "ca.pool.ntp.org"
Set-ItemProperty . "(Default)" "0"
Set-Location HKLM:\SYSTEM\CurrentControlSet\services\W32Time\Parameters
Set-ItemProperty . NtpServer "ca.pool.ntp.org"
Pop-Location
Stop-Service w32time
Start-Service w32time

Note: This script overwrites whatever is currently in the parameter "0". To use properly, you should have your script make your NTP server the next sequential entry.

like image 548
Weehooey Avatar asked Jul 06 '13 21:07

Weehooey


1 Answers

From a bit of googling about w32tm vs control panel date/time, I found this, which appears to be what you need.

Hope that helps you out :-)

like image 104
Graham Gold Avatar answered Oct 03 '22 04:10

Graham Gold