【发布时间】:2017-11-13 11:17:44
【问题描述】:
我想创建一个在周一至周五早上 6 点到晚上 9 点之间运行的作业,并以 15 分钟的间隔触发,如果运行时间超过 10 分钟,该作业应该终止。
我试过下面的代码:
$action = New-ScheduledTaskAction -Execute Powershell.exe
$trigger = New-ScheduledTaskTrigger -Weekly -At 6:30AM -DaysOfWeek 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'
$task = Register-ScheduledTask -TaskName "TaskName" -Trigger $trigger -Action $action -RunLevel Highest
$task.Triggers.ExecutionTimeLimit = 'PT30M'
$task.Triggers.Repetition.Duration = 'PT15H'
$task.Triggers.Repetition.Interval= 'PT15M'
$task.Triggers.Repetition.Duration = 'PT15H'
$task | Set-ScheduledTask -User "UserName" -Password "Password"
如果工作超过 10 分钟,我已经实现了除了终止工作之外的所有其他目标。 我遇到了错误。
The property 'ExecutionTimeLimit' cannot be found on this object. Verify that the property exists and can be set.
At line:4 char:1
+ $task.Triggers.ExecutionTimeLimit = 'PT10M'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
请帮我解决这个问题。在此先感谢。
【问题讨论】:
标签: windows powershell scheduled-tasks taskscheduler