New-ScheduledTaskSettingsSet ExecutionTimeLimit: How to not have one?

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of MichaelV MichaelV 3 weeks ago.

  • Author
  • #71422
    Profile photo of Bryn Spears
    Bryn Spears

    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?


  • #71972
    Profile photo of MichaelV

    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"

You must be logged in to reply to this topic.