(07-22-2025, 11:55 PM)admin Wrote: It doesn't automatically synchronize the time when the internet connection is stable?
No, it doesn’t auto sync for some reason. I’ve put together a PowerShell script with a 2-minute delayed startup (to give the network enough time to come online) to handle the sync.
PHP Code:
# Sync-WindowsTime.ps1
# Self-elevation block: Relaunch with admin rights if necessary
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()
).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) {
Write-Host "Relaunching PowerShell as Administrator..."
$params = "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`""
Start-Process powershell.exe -Verb RunAs -ArgumentList $params
exit
}
# Check the status of Windows Time service
$service = Get-Service -Name w32time -ErrorAction SilentlyContinue
if ($null -eq $service) {
Write-Host "Windows Time service (w32time) not found."
exit 1
}
if ($service.Status -ne 'Running') {
Write-Host "Windows Time service is not running. Starting the service..."
Start-Service -Name w32time
Start-Sleep -Seconds 2
} else {
Write-Host "Windows Time service is already running."
}
# Force time sync
Write-Host "Forcing time synchronization..."
w32tm /resync /force
Write-Host "Time synchronization command executed."
Start-Sleep -Seconds 2
exit