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:".
The value is PT0S (ISO 8601 timespan for 0:00:00).
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!!
Register-ScheduledTask : The task XML contains a value which is incorrectly formatted or out of range. (44,48):ExecutionTimeLimit:P99999999DT23H59M59S
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 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 working on this issue (https://github.com/PowerShell/xComputerManagement/issues/115) 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:
$settings = New-ScheduledTaskSettingsSet $settings.ExecutionTimeLimit = 'PT0S'
On Windows Server 2016:
$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!
You must be logged in to reply to this topic.