Scheduled Task Trigger - Synchronize Across Time Zones

Summary

When creating a scheduled task trigger using the Task Scheduler UI, the setting Synchronize Across Time Zones is disabled by default. However, the PowerShell cmdlet New-ScheduledTaskTrigger exhibits the opposite behaviour.

I wanted to understand the purpose of this setting in order to determine whether I should enable or disable it, this post documents my findings.

Scheduled Task Settings

Behind the scenes, a scheduled task is stored as an XML file in C:\Windows\System32\Tasks.

To signify that Synchronize Across Time Zones is disabled, the time portion of a trigger’s start time (referred to as the StartBoundary) is recorded in the XML file as Thh:mm:ss. Whereas when enabled it’s recorded as Thh:mm:ssZ, the trailing Z denotes zero UTC offset.

‘Synchronize Across Time Zones’ Explained

Task Scheduler Trigger UI

When Disabled

When Synchronize Across Time Zones is disabled, a trigger’s start date/time is relative to the computer’s time zone. For example, if a trigger’s start date/time is set to 10am on the 1st February 2020, the task will run once that date/time has been reached according to the computer’s time zone.

When Enabled

When Synchronize Across Time Zones is enabled, the specified date/time is converted to its equivalent in Coordinated Universal Time (UTC). For example, a start date/time of 10am on the 1st February 2020 on a computer with a time zone of Central European Standard Time (UTC+1) would be 9am on the 1st February 2020 when converted to UTC.

Within the task’s XML file, the date/time is recorded in its UTC form as 2020-02-01T09:00:00Z:

<Triggers>
  <TimeTrigger>
    <StartBoundary>2020-02-01T09:00:00Z</StartBoundary>
    <Enabled>true</Enabled>
  </TimeTrigger>
</Triggers>

The Task Scheduler UI always renders the time according to the computer’s time zone:

Task Scheduler Trigger UI

If the computer’s time zone is changed (something a user may do if travelling to a location in a different time zone) the task will continue to run according to the UTC time recorded in the task’s XML file.

Additional Info:

Powershell’s New-ScheduledTaskTrigger cmdlet

As mentioned in the summary, the default behaviour of the Task Scheduler UI is to create a trigger with Synchronize Across Time Zones disabled, whereas New-ScheduledTaskTrigger does the opposite.

Whether this matters or not depends on the use case. If the time zone of a device never changes (excluding DST) then it effectively makes no difference whether Synchronize Across Time Zones is enabled or disabled.

If I want to disable Synchronize Across Time Zones, the workaround I use is to supply New-ScheduledTaskTrigger with a dummy date/time and then overwrite the StartBoundary property with the actual date/time I require, EG:

$Date = Get-Date -Date "2020-02-01 10:00:00"
$Trigger = New-ScheduledTaskTrigger -Once -At (Get-Date -Day 1 -Month 1 -Year 1 -Hour 0)
$Trigger.StartBoundary = (Get-Date -Date $Date -Format 'yyyy-MM-ddTHH:mm:ss')

Comments

Leaving comments has been disabled for this post.

Copyright © 2018 - 2022 thecliguy.co.uk
For details, see Licences and Copyright