前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >获取Windows Ntp Server列表

获取Windows Ntp Server列表

原创
作者头像
Windows技术交流
修改2024-09-11 07:57:16
2070
修改2024-09-11 07:57:16
举报
文章被收录于专栏:Windows技术交流

获取Windows Ntp Server列表的powershell,在本地电脑、阿里云、腾讯云测试有效(搞这么复杂主要是保障排序,阿里云那种,如果不排序就是文档后面一句话命令的那种效果,有点乱)

代码语言:txt
复制
$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:

代码语言:txt
复制
#(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] }

用下面的.bat设置可靠的腾讯云校时

代码语言:txt
复制
@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 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 用下面的.bat设置可靠的腾讯云校时
相关产品与服务
云服务器
云服务器(Cloud Virtual Machine,CVM)提供安全可靠的弹性计算服务。 您可以实时扩展或缩减计算资源,适应变化的业务需求,并只需按实际使用的资源计费。使用 CVM 可以极大降低您的软硬件采购成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档