简体   繁体   English

触发任务调度程序来自powershell的作业

[英]Trigger task scheduler Job from powershell

I want to create a job that runs between the hours of 6 AM and 9 PM Monday through Friday and triggers in an interval of 15 min and the job should terminate if it runs longer than 10 minutes. 我想创建一个在星期一到星期五的早上6点到晚上9点之间运行的作业,并在15分钟的时间间隔内触发,如果运行时间超过10分钟,作业应该终止。

I have tried the below code: 我试过以下代码:

$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"

I have achieved all other objectives except the termination of job if it runs more than 10 min. 除了工作终止超过10分钟,我已经实现了所有其他目标。 I am getting below error. 我收到了以下错误。

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

Please help me to over come this issue.Thanks in advance. 请帮我解决这个问题。谢谢。

I think task settings executionlimit is what you are looking for : 我认为任务设置的执行限制是你正在寻找的:

$task.Settings.ExecutionTimeLimit =  'PT30M'

a commandlet version of the same: 一个相同的命令行开发版:

 $settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Minutes 30)

 Set-ScheduledTask -TaskName 'taskname' -Settings $settings

for reference on the property : https://technet.microsoft.com/en-us/library/cc722178(v=ws.11).aspx 供参考: https//technet.microsoft.com/en-us/library/cc722178(v = ws.11).aspx

A useful discussion regarding trigger executionlimit and task setting executionlimit : https://superuser.com/questions/506662/what-is-the-difference-between-stop-the-task-if-it-runs-longer-than-inside-tri 关于触发器执行限制和任务设置执行限制的有用讨论: https//superuser.com/questions/506662/what-is-the-difference-between-stop-the-task-if-it-runs-longer-than-inside -三

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用触发器类型过滤 Powershell 删除任务计划程序中的任务? - Delete a task in Task Scheduler using Powershell filtering on trigger type? Powershell Monitor任务计划程序 - Powershell monitor task scheduler 在任务计划程序中运行PowerShell - Running PowerShell in Task Scheduler VBScript 不会从从 Windows 任务计划程序运行的 Powershell 脚本中运行 - VBScript will not run from Powershell script that runs from Windows Task Scheduler 从 Windows 调度程序调用时,Powershell 触发 ACR BUILD 失败 - Powershell to trigger ACR BUILD failing when called from windows scheduler Windows 任务计划程序中的 PowerShell 脚本无法正常工作 - PowerShell script doesn't work correctly from Windows Task Scheduler 来自 Windows 10 任务调度程序的 Powershell 脚本未启动 Chrome - Powershell script from Windows 10 task scheduler not launching Chrome Windows 任务计划程序未从 Powershell 脚本启动程序 - Windows Task Scheduler not starting program from Powershell script 任务计划程序应用程序退出触发器 - Task Scheduler Application Exit Trigger 使用Windows Task Scheduler运行的PowerShell脚本未运行SQL Server SSIS DTEXEC.EXE作业 - PowerShell script run using Windows Task Scheduler is not running a SQL Server SSIS DTEXEC.EXE job
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM