Share via

Powershell: New-ScheduledTaskTrigger cmdlet with indefinite duration in Windows 10 and windows 2016 server

Anonymous
2020-10-29T14:57:41+00:00

Goal: To add a new trigger to a schedule task that runs every 3 minutes for an indefinite duration.

Please note the commands should work on both windows 2012 server and windows 2016 server.

I am using New-ScheduledTaskTrigger cmdlet to create a new trigger object as below

New-ScheduledTaskTrigger -Once -At $startTime -RepetitionInterval (New-TimeSpan -Minutes 3) -RepetitionDuration ([TimeSpan]::MaxValue)

And using this trigger with Set-ScheduledTask.

Windows 2016 server behavior:

  • An error is thrown as below

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

(12,42):Duration:P99999999DT23H59M59S

  • But removing the "RepetitionDuration" parameter would work as expected and creates a trigger with indefinite duration.

Windows 2012 server behavior:

  • New-ScheduledTasTrigger command as provided above works fine
  • But if I remove "RepetitionDuration" parameter (to make it work on windows 2016), this throws an error as below 

New-ScheduledTaskTrigger : The RepetitionInterval and RepetitionDuration Job trigger parameters must be specified together.

Please help me to resolve this. Let me know in case any additional information is required.

Powershell version information in windows 2012 (Output of $PSVersionTable)

Name                           Value                                                                                                                   

----                           -----                                                                                                                   

PSVersion                      5.1.14409.1005                                                                                                          

PSEdition                      Desktop                                                                                                                 

PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                 

BuildVersion                   10.0.14409.1005                                                                                                         

CLRVersion                     4.0.30319.42000                                                                                                         

WSManStackVersion              3.0                                                                                                                     

PSRemotingProtocolVersion      2.3                                                                                                                     

SerializationVersion           1.1.0.1 

Powershell version information in windows 2016 (Output of $PSVersionTable)

Name                           Value                                                                                                                                                                       

----                           -----                                                                                                                                                                       

PSVersion                      5.1.14393.3471                                                                                                                                                              

PSEdition                      Desktop                                                                                                                                                                     

PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                     

BuildVersion                   10.0.14393.3471                                                                                                                                                             

CLRVersion                     4.0.30319.42000                                                                                                                                                             

WSManStackVersion              3.0                                                                                                                                                                         

PSRemotingProtocolVersion      2.3                                                                                                                                                                         

SerializationVersion           1.1.0.1

Windows for home | Other | Apps

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2020-10-30T05:17:57+00:00

    Thank you Igor. I posted the question in Q&A forum.

    Was this answer helpful?

    0 comments No comments
  2. Igor Leyko 111K Reputation points Independent Advisor
    2020-10-29T16:26:12+00:00

    Hi Chandan,

    I'm Independent Advisor not Microsoft employee or support person. I have deep enough Windows knowledge and you may trust me. It's a pleasure for me to help others and I'll do all my best to help you.

    It is more effective to ask server related questions at Q&A forum https://docs.microsoft.com/en-us/answers/index....

    It is oriented to admins and corporate users, and this forum - to home users so local experts may have no corresponding knowledge, sorry.

    Was this answer helpful?

    0 comments No comments