问题
I am installing a scheduled task using a PowerShell script, but I would like it to retry 3 times on failure, how can I add this to my scheduled task registration script?
$dropLocation = "C:\Tasks\"
$Action = New-ScheduledTaskAction -Execute "$dropLocation\Task.exe"
$Trigger = New-ScheduledTaskTrigger -Daily -At 10:15pm
$Settings = New-ScheduledTaskSettingsSet -RestartCount:3
Register-ScheduledTask -Action $Action -Trigger $Trigger -TaskName "$taskName" -Settings $Settings -Description "TaskDescription"
回答1:
Specifying the retry count is not enough. You have to specify two parameters:
The retry count and the retry interval.
To retry up to three times with an interval of 1 minute, your settings should look like this:
$Settings = New-ScheduledTaskSettingsSet -RestartCount:3 -RestartInterval (New-TimeSpan -Minutes 1)
来源:https://stackoverflow.com/questions/35082121/retry-attempts-on-failure-when-installing-scheduled-task-with-powershell