我们希望使用Windows PowerShell在未连接到域的Windows 7工作站上设置特定的NTP服务器.目标是运行许多脚本来标准化/加速/简化非域工作站的初始设置.
我们尝试过:
Push-Location
Set-Location HKLM:\SYSTEM\CurrentControlSet\services\W32Time\Parameters
Set-ItemProperty . NtpServer "ca.pool.ntp.org"
Pop-Location
Run Code Online (Sandbox Code Playgroud)
这个脚本:
w32tm /config /manualpeerlist:ca.pool.ntp.org /syncfromflags:manual /update
Stop-Service w32time
Start-Service w32time
Run Code Online (Sandbox Code Playgroud)
在运行这两个脚本(使用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
Run Code Online (Sandbox Code Playgroud)
注意:此脚本将覆盖当前参数"0"中的任何内容.要正确使用,您应该让脚本使您的NTP服务器成为下一个顺序条目.
归档时间: |
|
查看次数: |
35557 次 |
最近记录: |