title: setting NTP server on Windows machine using PowerShell
body: <p>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. </p>
  
  <p>We have tried:</p>
  
  <pre><code>Push-Location
  Set-Location HKLM:\SYSTEM\CurrentControlSet\services\W32Time\Parameters
  Set-ItemProperty . NtpServer "ca.pool.ntp.org"
  Pop-Location
  </code></pre>
  
  <p>And this script:</p>
  
  <pre><code>w32tm /config /manualpeerlist:ca.pool.ntp.org /syncfromflags:manual /update
  Stop-Service w32time
  Start-Service w32time
  </code></pre>
  
  <p>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.</p>
  
  <p><em>this is the code which was developed from Graham Gold's response below and works:</em></p>
  
  <pre><code>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
  </code></pre>
  
  <p><strong>Note:</strong> 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.</p>