powershell - 使用 PowerShell 在 Windows 机器上设置 NTP 服务器

标签 powershell

我们希望使用 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

运行这两个脚本(使用管理员权限)后,我们检查注册表并在以下位置找到 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 服务器成为下一个顺序条目。

最佳答案

通过对 w32tm 与控制面板日期/时间的一些谷歌搜索,我发现 this ,这似乎是您所需要的。

希望能帮到你:-)

关于powershell - 使用 PowerShell 在 Windows 机器上设置 NTP 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17507339/

相关文章:

string - Windows gc 替换显示\n 而不是新行

powershell - 使用Powershell Windows 2008导出特定进程

powershell - 在Powershell中,有一种便捷的方法来转储属于组的所有dicom元素

powershell - 逐个文件捕获 `Get-ChildItem` 错误

sql - 如何使用 PowerShell 编辑 SQL 作业步骤

powershell - 查找具有特定扩展名的所有文件,按创建时间对它们进行排序并使用新名称复制它们

powershell - 发布 Web App 添加任务所需的代理配置

带有包含的 Powershell PS session 脚本文件

PowerShell 桌面变量

wcf - 使用 new-webproxyservice 从 powershell 调用 wcf 的奇怪行为