Author Posts

May 24, 2017 at 2:50 pm

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.
(44,48):ExecutionTimeLimit:P99999999DT23H59M59S

https://gist.github.com/brynsp/1c46c6b6b0e5165c7ca31188af5ca629.js

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

Thanks,
~bryn

June 2, 2017 at 9:36 am

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"

June 29, 2017 at 3:04 pm

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)
https://gist.github.com/brynsp/1c46c6b6b0e5165c7ca31188af5ca629

Second:
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?

December 7, 2017 at 9:31 am

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:
You need to create the settings object and then manually set the ExecutionTimeLimit to 'PT0S'
E.g.

$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:
E.g.

$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!