Fixing Scheduled Task triggers running an hour later / earlier after DST via Powershell
Posted by Q_O_T@reddit | sysadmin | View on Reddit | 0 comments
I'm writing this in case someone else runs into the issue I had and needs a fix. Its not a perfect fix but it works. I'm aware that the best option going forward is to set the servers to use UTC time but that's not currently on the table.
After DST ( Daylight Savings Time ) occurred on Sunday, we noticed scheduled tasks on a new server were not running at the same time. They were now an hour off. These scheduled tasks had several triggers set to go off during different times of the day. The triggers had "synchronize across time zones" box checked. That was what was causing the issue.
Not wanting to go through each scheduled task and each trigger and uncheck that box, I looked for a way to do it via PowerShell. I didn't have any luck until i stumbled found this blog article. https://www.thecliguy.co.uk/2020/02/09/scheduled-task-trigger-synchronize-across-time-zones/
All you need to do is set the "StartBoundary" property for the trigger to not have UTC in the string. So instead of:
2024-11-06T12:00:00-8
You would do:
2024-11-06T12:00:00
There's probably a better way to script this, but it works. Put the scheduled task names in the $tasknames variables. If there's a folder/path issue you'll need to modify things to work.
$tasknames = @()
foreach ($taskname in $tasknames){
$task = Get-ScheduledTask -TaskName $taskname
$newtriggers=@()
foreach ($trigger in $task.Triggers) {
`$time=[datetime]$trigger.StartBoundary`
`[string]$stringtime=get-date -date $time -format 'HH:mm:ss'`
$today = get-date -format 'yyyy-MM-ddT'
`$newtime = $today + $stringtime`
`$newtrigger = $trigger`
`$newtrigger.startboundary = $newtime`
`$newtriggers += $newtrigger`
}
Set-scheduledtask -taskname $taskname -trigger $newtriggers
}