I'm trying to create a task which will repeat every 5 minutes indefinitely through powershell. However, I cannot figure out a way to do this through all my searching. New-TimeSpan -Days 9999
appears to be the maximum value, and no matter what I do I cannot get the time to go over 9999 days.
Here's the trigger:
$trigger = New-ScheduledTaskTrigger -Once -At $date -RepetitionDuration (New-TimeSpan -Days 9999) -RepetitionInterval (New-TimeSpan -Minutes 5)
$PSVersionTable.PSVersion
reports what I assume to be v4, here's the output:
Major Minor Build Revision
4 0 -1 -1
Subexpression operator $( ) For a single result, returns a scalar. For multiple results, returns an array. Use this when you want to use an expression within another expression. For example, to embed the results of command in a string expression. PowerShell Copy.
The While statement in PowerShell is used to create a loop that runs a command or a set of commands if the condition evaluates to true. It checks the condition before executing the script block. As long as the condition is true, PowerShell will execute the script block until the condition results in false.
The New-TimeSpan cmdlet creates a TimeSpan object that represents a time interval. You can use a TimeSpan object to add or subtract time from DateTime objects. Without parameters, a New-TimeSpan command returns a TimeSpan object that represents a time interval of zero.
Use -RepetitionDuration ([timespan]::MaxValue)
As of today, this gives you 10,675,199 days (almost 30,000 years).
See https://superuser.com/questions/403595/creating-a-scheduled-task-in-windows-that-will-run-at-intervals-indefinitely
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With