
获取Windows Ntp Server列表的powershell,在本地电脑、阿里云、腾讯云测试有效(搞这么复杂主要是保障排序,阿里云那种,如果不排序就是文档后面一句话命令的那种效果,有点乱)
$ntpServers = (Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Parameters").NtpServer -split " " | ForEach-Object { ($_ -split ",")[0] }
$sortedNtpServers = $ntpServers | Sort-Object @{Expression={($_ -split '\.')[1]}; Descending=$false}, @{Expression={[int](($_ -split '\D+')[1])}; Descending=$false}
$sortedNtpServers



如果简单点的化,就一句powershell:
#(Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Parameters").NtpServer
#或
((Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Parameters").NtpServer -split " ") | ForEach-Object { ($_ -split ",")[0] }
#设置可靠的腾讯云校时
reg add "HKLM\SYSTEM\CurrentControlSet\Services\W32Time\Config" /v UtilizeSslTimeData /t REG_DWORD /d 0 /f
cmd.exe /c 'sc.exe config w32time start= auto'
net stop w32time
net start w32time
w32tm /config /manualpeerlist:"time.windows.com,0x8 time.tencent.com,0xa ntp.tencent.com,0xa ntpupdate.tencentyun.com,0xa time1.tencentyun.com,0xa time2.tencentyun.com,0xa time3.tencentyun.com,0xa time4.tencentyun.com,0xa time5.tencentyun.com,0xa" /syncfromflags:manual /reliable:yes /update
w32tm /query /configuration
w32tm /query /source
w32tm /query /peers
w32tm /resync /rediscover /nowait
start-sleep 2
w32tm /resync /rediscover /nowait
start-sleep 2
w32tm /resync /rediscover /nowait
((Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Parameters").NtpServer -split " ") | ForEach-Object { ($_ -split ",")[0] }
@"
net start w32time 2>nul
w32tm /resync
w32tm /resync
w32tm /resync
"@ | Out-File -FilePath "C:\w32time.bat" -Encoding ASCII
schtasks /create /tn "\w32tm_resync" /ru SYSTEM /rl highest /tr "cmd.exe /c C:\w32time.bat" /sc onstart /delay 0000:03 /f
#schtasks /change /tn "\w32tm_resync" /st 00:00 /sd 2000/01/01
#reg query "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation" /v RealTimeIsUniversal
#reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation" /v RealTimeIsUniversal /d 1 /t REG_DWORD /f
#reg query "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation" /v RealTimeIsUniversal
#get-wmiobject -class win32_service | where{$_.PathName -match "qcloud"}| select -property Name,StartMode,State,PathName
用开头的排序list ntpserver的复杂命令查询

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。