我们希望使用Windows PowerShell在未连接到域的Windows 7工作站上设置特定的NTP服务器。目标是运行许多脚本来标准化/加速/简化非域工作站的初始设置。
我们尝试过:
Push-Location
Set-Location HKLM:\SYSTEM\CurrentControlSet\services\W32Time\Parameters
Set-ItemProperty . NtpServer "ca.pool.ntp.org"
Pop-Location
这个脚本:
w32tm /config /manualpeerlist:ca.pool.ntp.org /syncfromflags:manual /update
Stop-Service w32time
Start-Service w32time
运行两个脚本(使用admin priv)后,我们检查注册表并找到NtpServer:HKLM:\ SYSTEM \ CurrentControlSet \ services \ W32Time \ Parameters已更新为“ca.pool.ntp.org”但查看控制面板>我们发现旧的NTP服务器仍然列出的日期和时间 - 即使计算机已重新启动。
这是根据Graham Gold的回复开发的代码,有效:
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
注意:此脚本会覆盖参数“0”中当前的内容。要正确使用,您应该让脚本使您的NTP服务器成为下一个顺序条目。