New-ScheduledTaskSettingsSet ExecutionTimeLimit: How to not have one?

I’m attempting to create a scheduled task via PowerShell, but I’m running into a problem building the SettingsSet.

In the Task Scheduled MMC console the parameter in question is under Settings: “Stop the task if it runs longer than:”.
As part of trying to figure this out I have done the following:

  • Created a task with the checkbox unchecked for the setting
  • Exported the task to an .xml file

The value is PT0S (ISO 8601 timespan for 0:00:00).
When I check the checkbox to enable the setting and leave the default duration for 3 days and check the setting is PT72H as I would expect.

Knowing this in my code I set the ExecutionTimeLimit to 0:00:00; however, when the task is created the timespan is set to PT72H!!
If I set the ETL to 0:01:00 it is set to PT1M.
If I try to use [timespan]::MaxValue it throws an error

Register-ScheduledTask : The task XML contains a value which is incorrectly formatted or out of range.

Is it possible to create a task without an execution time limit? If so, what am I missing?


I ran into the same problem today when I wanted to create a scheduled task using PowerShell.
The [TimeSpan]::MaxValue have worked before, but not on this server (Windows Server 2016). Works fine on my workstation (Windows 10).

The repetition duration max value in my case is [timeSpan] “24855.03:14:07”

First: Here is the correct URL to the Gist (I think, there is no preview in this forum and I’m new to posting here)

I’m running into this problem on Windows Server 2012 R2 as well. Has anyone else seen this behavior on other versions?
If it is a bug, is there any way to see if it is a known one?

I’m working on this issue (xScheduledTask ExecutionTimeLimit = '00:00:00' sets ExecutionTimeLimit to 3 days · Issue #115 · dsccommunity/ComputerManagementDsc · GitHub) over on the xScheduledTask resource in the DSC resource kit and have found that the method to do this on Windows Server 2012 R2 and Windows Server 2016 are different:

On Windows Server 2012 R2:
You need to create the settings object and then manually set the ExecutionTimeLimit to ‘PT0S’

$settings = New-ScheduledTaskSettingsSet
$settings.ExecutionTimeLimit = 'PT0S'

On Windows Server 2016:
You need to create the settings object and pass in a timespan string of ‘00:00:00’ to the -ExecutionTimeLimit parameter:

$settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit '00:00:00'

You can then pass the $settings object into the New-ScheduledTask as per the other comments.

Hopefully this helps anyone else running into this problem!