
执行这个powershell生成的.bat内容用记事本打开是连成一行的,用notepad++打开又是显示4行的,如何调整代码让前者也显示4行
powershell:
@"
net start w32time 2>nul
w32tm /resync
w32tm /resync
w32tm /resync
"@ | Out-File -FilePath "C:\w32time.bat" -Encoding ASCII
【最终方案】
推荐:
$lines = @(
"net start w32time 2>nul",
"w32tm /resync",
"w32tm /resync",
"w32tm /resync"
)
$lines | Out-File -FilePath "C:\w32time.bat" -Encoding ASCII
备选:
$content = @"
net start w32time 2>nul
w32tm /resync
w32tm /resync
w32tm /resync
"@
$content -replace "`n", "`r`n" | Out-File -FilePath "C:\w32time.bat" -Encoding ASCII -NoNewline


设置可靠的腾讯云校时
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] }
$lines = @(
"net start w32time 2>nul",
"w32tm /resync",
"w32tm /resync",
"w32tm /resync"
)
$lines | 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:05 /f
schtasks /change /tn "\w32tm_resync" /st 00:00 /sd 2000/01/01
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。