Forum Discussion
ChandanVysyaraju
Oct 29, 2020Copper Contributor
Powershell: New-ScheduledTaskTrigger cmdlet with indefinite duration in Windows 10 and windows 2016
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
No RepliesBe the first to reply