导入Windows自定义镜像如何内网ntp server校时

2023-09-12 19:24:48 浏览数 (1)

做镜像前,执行下这个脚本

timesync_per_min.ps1.zip

内容如下(我配置开机计划任务在开机时校时,校时SpecialPollInterval是5秒,根据各人需求,可以适当调大,不调也可以,如果调的话,注意要满足SpecialPollInterval∈【2^MinPollInterval, 2^MaxPollInterval】,比如5∈【2^2, 2^6】):

代码语言:javascript复制
schtasks.exe /delete /tn "timesync_per_min" /F 2>&1 > $null
schtasks.exe /delete /tn "time sync" /F 2>&1 > $null
schtasks.exe /delete /tn "timesync" /F 2>&1 > $null

$configfile =@"
@echo off`n`r
net stop w32time 2>&1 > nul`n`r
#w32tm /unregister 2>&1 > nul`n`r
#w32tm /register 2>&1 > nul`n`r
sc.exe triggerinfo w32time delete 2>&1 > nul`n`r
sc.exe config w32time start= auto 2>&1 > nul`n`r
sc.exe triggerinfo w32time start/networkon stop/networkoff 2>&1 > nul`n`r
reg add "HKEY_LOCAL_MACHINESOFTWAREPoliciesMicrosoftW32TimeConfig" /v MaxNegPhaseCorrection /t REG_DWORD /d 4294967295 /f`n`r
reg add "HKEY_LOCAL_MACHINESOFTWAREPoliciesMicrosoftW32TimeConfig" /v MaxPosPhaseCorrection /t REG_DWORD /d 4294967295 /f`n`r
reg add "HKEY_LOCAL_MACHINESOFTWAREWow6432NodePoliciesMicrosoftW32TimeConfig" /v MaxNegPhaseCorrection /t REG_DWORD /d 4294967295 /f`n`r
reg add "HKEY_LOCAL_MACHINESOFTWAREWow6432NodePoliciesMicrosoftW32TimeConfig" /v MaxPosPhaseCorrection /t REG_DWORD /d 4294967295 /f`n`r
reg add "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesw32timeConfig" /v MaxNegPhaseCorrection /t REG_DWORD /d 4294967295 /f`n`r
reg add "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesw32timeConfig" /v MaxPosPhaseCorrection /t REG_DWORD /d 4294967295 /f`n`r
reg add "HKLMSYSTEMCurrentControlSetServicesW32TimeConfig" /v "EventLogFlags" /t REG_DWORD /d 3 /f`n`r
reg add "HKLMSYSTEMCurrentControlSetServicesW32TimeTimeProvidersNtpClient" /v "EventLogFlags" /t REG_DWORD /d 3 /f`n`r
reg add "HKLMSYSTEMCurrentControlSetServicesW32TimeTimeProvidersNtpServer" /v "EventLogFlags" /t REG_DWORD /d 3 /f`n`r
reg add "HKLMSYSTEMCurrentControlSetServicesW32TimeConfig" /v "MinPollInterval" /t REG_DWORD /d 2 /f`n`r
reg add "HKLMSYSTEMCurrentControlSetServicesW32TimeConfig" /v "MaxPollInterval" /t REG_DWORD /d 6 /f`n`r
reg add "HKLMSYSTEMCurrentControlSetServicesW32TimeConfig" /v "UpdateInterval" /t REG_DWORD /d 5 /f`n`r
reg add "HKLMSYSTEMCurrentControlSetServicesW32TimeConfig" /v "SpikeWatchPeriod" /t REG_DWORD /d 5 /f`n`r
reg add "HKLMSYSTEMCurrentControlSetServicesW32TimeConfig" /v "PhaseCorrectRate" /t REG_DWORD /d 14 /f`n`r
reg add "HKLMSYSTEMCurrentControlSetServicesW32TimeTimeProvidersNtpClient" /v "SpecialPollInterval" /t REG_DWORD /d 5 /f`n`r
reg add "HKLMSYSTEMControlSet001ServicesW32TimeTimeProvidersNtpClient" /v "SpecialPollInterval" /t REG_DWORD /d 5 /f`n`r
reg add "HKLMSYSTEMControlSet002ServicesW32TimeTimeProvidersNtpClient" /v "SpecialPollInterval" /t REG_DWORD /d 5 /f`n`r
reg add "HKLMSOFTWAREPoliciesMicrosoftW32TimeTimeProvidersNtpClient" /v "SpecialPollInterval" /t REG_DWORD /d 5 /f`n`r
reg add "HKLMSOFTWAREWow6432NodePoliciesMicrosoftW32TimeTimeProvidersNtpClient" /v "SpecialPollInterval" /t REG_DWORD /d 5 /f`n`r
net start w32time`n`r
w32tm /config /manualpeerlist:"time1.tencentyun.com,0x8 time2.tencentyun.com,0xa time3.tencentyun.com,0xa time4.tencentyun.com,0xa time5.tencentyun.com,0xa" /syncfromflags:manual /reliable:yes /update`n`r
w32tm /resync /rediscover /nowait`n`r
w32tm /resync /rediscover /nowait`n`r
w32tm /resync /rediscover /nowait`n`r
"@

$configfile|Out-File -FilePath C:Windowstimesync.bat -Encoding ascii -Force

schtasks /create /tn "timesync_per_min" /ru SYSTEM /rl highest /tr "cmd.exe /c C:Windowstimesync.bat" /sc onstart /delay 0000:59 /f
schtasks /change /tn "timesync_per_min" /st 00:00 /sd 1900/01/01

如果是已经买定的机器,执行脚本后运行下计划任务

代码语言:javascript复制
schtasks /Run /TN "timesync_per_min"
或
Start-ScheduledTask -TaskName "timesync_per_min"

0 人点赞