我有这个脚本来创建使用PowerShell的计划任务,但是我无法弄清楚如何设置和到期日期","以最高权限运行&#34 34;并且"如果任务的运行时间超过"则停止任务。
$taskName = "TestTask"
$user = "<....>"
$password = "<...>"
$action = New-ScheduledTaskAction -Execute "notepad.exe"
$trigger = New-ScheduledTaskTrigger -Weekly -AT "23:00" -DaysOfWeek 'Monday', 'Tuesday', 'Wednesday'
$settings = New-ScheduledTaskSettingsSet
$inputObject = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings
Register-ScheduledTask -TaskName $taskName -InputObject $inputObject -User $user -Password $password
答案 0 :(得分:6)
您需要在New-ScheduledTaskSettingsSet命令中指定适当的参数,例如
$settings = New-ScheduledTaskSettingsSet `
-ExecutionTimeLimit ([TimeSpan]::FromHours(2)) `
-DeleteExpiredTaskAfter ([TimeSpan]::FromDays(60)
Register-ScheduledTask ... -Settings $settings -RunLevel Highest
有关New-ScheduledTaskSettingsSet命令的更多信息,请查看此帮助主题。