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?

voidstate
  • 249
  • 2
  • 8
red888
  • 4,183
  • 18
  • 64
  • 111

3 Answers3

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
haymansfield
  • 121
  • 5
0

If you skip the -RepetitionDuration it defaults to Indefinite.

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)
Tim Penner
  • 1,889
  • 14
  • 22
  • 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 '16 at 21:16
  • 2
    -1. `AtStartup` does not support `RepetitionInterval`. @red888 what did you end up using as a solution? – Justin Helgerson Sep 01 '16 at 00:22