Skip to content

Instantly share code, notes, and snippets.

@ian-moore
Last active May 18, 2018 19:42
Show Gist options
  • Save ian-moore/03ca5c9cdf70ac9452fa50ba85254921 to your computer and use it in GitHub Desktop.
Save ian-moore/03ca5c9cdf70ac9452fa50ba85254921 to your computer and use it in GitHub Desktop.
$taskName = 'ForceClockSynchronization'
$trigger = new-scheduledtasktrigger `
-once `
-at (get-date) `
-RepetitionInterval (New-TimeSpan -Hours 1) `
-RepetitionDuration ([system.timespan]::MaxValue)
$stopService = new-scheduledtaskaction `
-execute net `
-argument 'stop w32time'
$startService = new-scheduledtaskaction `
-execute net `
-argument 'start w32time'
$sync = new-scheduledtaskaction `
-execute w32tm `
-argument '/resync'
register-scheduledtask `
-user 'NT AUTHORITY\LOCALSERVICE' `
-action @($stopService, $startService, $sync) `
-trigger $trigger `
-TaskName $taskName `
-description 'Force windows time service to run and synchronize the system clock.'
start-scheduledtask -taskname $taskName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment