4
我想要創建一個作業,該作業在週一至週五上午6點到晚上9點之間運行,並以15分鐘爲間隔觸發,如果運行時間超過10分鐘,則該作業應該終止。從powershell觸發任務計劃程序作業
我曾嘗試下面的代碼:
$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
請幫我解決這個問題。提前感謝。
謝謝Abhijith。它有幫助 – Venkatakrishnan