Skip to content

Instantly share code, notes, and snippets.

@aivrit
Last active March 24, 2024 18:58
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aivrit/fdfee71e969ba62670ed0b87c26f3aad to your computer and use it in GitHub Desktop.
Save aivrit/fdfee71e969ba62670ed0b87c26f3aad to your computer and use it in GitHub Desktop.
Fix windows 10 time sync - workaround time service failure with a non-ntp manual setting approach
# this script was created to help sync time for machines running windows 10 where
# windows time service keeps failing, where time synchronization is constantly unsuccessfull
# this workaround approach has been taken since all other solutions on the web have not proven successfull in my case
# this solution should work for any windows 10 machine who has syncing issues
# run this script with admin privileges as a daily schedule on windows task scheduler and all your problems will be solved
# enjoy
$time = Invoke-RestMethod -Uri http://worldtimeapi.org/api/ip
$timezones = Get-TimeZone -ListAvailable
# there is no global standard in names of timezones nor a unique id of them
# worldtimeapi always has city name in last part of timezone field
# microsoft has city names in display name
# therefore current solution is to match those names based on city
foreach ($timezone in $timezones) {
if ($timezone.DisplayName.ToString() -match $time.timezone.Split("/")[-1]) {
$current_zone = $timezone
break
}
}
if (!$current_zone) {throw "Could'nt find time zone. exiting."}
Set-TimeZone -Name $current_zone.StandardName
Set-Date -Date (Get-Date -Date $time.datetime)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment