3

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?

3 Answers 3

0

Instead of using -Once -At you could be using -AtStartup or -AtLogon

-AtStartup

$trigger = New-ScheduledTaskTrigger -AtStartup -RepetitionInterval (New-TimeSpan -Minutes 5) -RepetitionDuration ([timespan]::MaxValue)

-AtLogon

$trigger = New-ScheduledTaskTrigger -AtLogon -RepetitionInterval (New-TimeSpan -Minutes 5) -RepetitionDuration ([timespan]::MaxValue)
2
  • 1
    Hmm I didn't think Atlogon supported repetitioninterval. When I run that command I get this error: New-ScheduledTaskTrigger : Parameter set cannot be resolved using the specified named parameters.
    – red888
    Mar 22, 2016 at 21:16
  • 2
    -1. AtStartup does not support RepetitionInterval. @red888 what did you end up using as a solution? Sep 1, 2016 at 0:22
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
0

If you skip the -RepetitionDuration it defaults to Indefinite.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .