0

I want to write a powershell script that creates a scheduled task in Windows, but if it fails, it will try again in an hour. Essentially, I want the equivalent of these boxes:

enter image description here

How would I modify the code below to be able to control those parameters?

$action = New-ScheduledTaskAction -Execute 'aggregate.pyw'
$trigger = New-ScheduledTaskTrigger -Daily -At 4:30am
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "Auto aggregate"

1 Answer 1

1

RestartCount

Specifies the number of times that Task Scheduler attempts to restart the task.

RestartInterval

Specifies the amount of time that Task Scheduler attempts to restart the task.

StartWhenAvailable

Indicates that Task Scheduler can start the task at any time after its scheduled time has passed.

You can browse all the other New-ScheduledTaskSettingsSet parameters here

$action = New-ScheduledTaskAction -Execute 'aggregate.pyw'
$trigger = New-ScheduledTaskTrigger -Daily -At 4:30am
$settings = New-ScheduledTaskSettingsSet -RestartCount:3 -RestartInterval (New-TimeSpan -Minutes 60) -StartWhenAvailable
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "Auto aggregate" -Settings $settings

enter image description here

You must log in to answer this question.

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