I suppose what I want is closer to a service, but I'd like to know if I could just accomplish this with a scheduled task.

I can create a task with these parameters:

$trigger = New-ScheduledTaskTrigger -Once -At 7am -RepetitionInterval (New-TimeSpan -Minutes 5) -RepetitionDuration ([timespan]::MaxValue)

But if the computer boots up after 7 AM the task never fires right?

How can I have a task that repeats every 5 mins no matter the time when the computer is on?


Solution 1:

I use the following method to achieve the desired result:

$T = New-ScheduledTaskTrigger -AtStartup
$RT = New-ScheduledTaskTrigger -Once -At 7am -RepetitionDuration (New-TimeSpan -Days 1)  -RepetitionInterval  (New-TimeSpan -Minutes 1)
$T.Repetition = $RT.Repetition