Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Infinite time in PowerShell?

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

like image 620
SamCyanide Avatar asked Apr 29 '15 20:04

SamCyanide


People also ask

What does $() mean in PowerShell?

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.

How do you loop in PowerShell?

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.

How do I use TimeSpan in PowerShell?

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.


1 Answers

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

like image 143
Tony Hinkle Avatar answered Oct 28 '22 02:10

Tony Hinkle