Fix Windows Time Sync with w32tm
Purpose Windows system clock drifting or refusing to sync. This script detects whether the machine is domain-joined and takes the correct NTP path automatically — no manual branching needed.
Approach If domain-joined → restore AD hierarchy sync (fighting domain policy with internet NTP is a support ticket waiting to happen) If workgroup/standalone → configure public NTP peers and force resync The Script Run as Administrator:
$isDomainJoined = (Get-CimInstance Win32_ComputerSystem).PartOfDomain if ($isDomainJoined) { Write-Host "Domain-joined — syncing from AD hierarchy" -ForegroundColor Cyan w32tm /config /syncfromflags:domhier /update Restart-Service w32time w32tm /resync /force } else { Write-Host "Workgroup machine — configuring public NTP" -ForegroundColor Cyan w32tm /config /manualpeerlist:"time.google.com time.cloudflare.com pool.ntp.org" /syncfromflags:manual /reliable:no /update Restart-Service w32time w32tm /resync /force } If Resync Fails Re-register the Windows Time Service, then re-run the script above: