使用 PowerShell 安装计划任务时重试失败 [英] Retry attempts on failure when installing scheduled task with PowerShell

查看:57
本文介绍了使用 PowerShell 安装计划任务时重试失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PowerShell 脚本安装计划任务,但我希望它在失败时重试 3 次,如何将其添加到我的计划任务注册脚本中?

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" 

推荐答案

指定重试次数是不够的.您必须指定两个参数:
重试次数和重试间隔.

Specifying the retry count is not enough. You have to specify two parameters:
The retry count and the retry interval.

要以 1 分钟为间隔重试最多 3 次,您的设置应如下所示:

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)

这篇关于使用 PowerShell 安装计划任务时重试失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆