获取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] }
@rem 以下代码另存为.bat即可设置可靠的腾讯云校时
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
w32tm /resync /rediscover /nowait
w32tm /resync /rediscover /nowait
schtasks.exe /create /tn "\start_w32time" /ru SYSTEM /rl highest /sc ONSTART /tr "c:\windows\system32\sc.exe start w32time" /f
schtasks /change /tn "\start_w32time" /ru SYSTEM /st 00:00 /sd 1900/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
用开头的排序list ntpserver的复杂命令查询
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。