简体   繁体   English

使用 powershell 在任务计划程序中更改任务的属性

[英]Change a property of a task in task scheduler using powershell

I have two triggers in a task.我在一个任务中有两个触发器。 The first one runs at a specific time.第一个在特定时间运行。 The second one starts at logon and runs every 10 minutes.第二个在登录时开始,每 10 分钟运行一次。 I have many similar tasks like this situation.我有很多类似的任务。 I want to use powershell to change the property from 10 minutes to 5 minutes and run indefinitely after logon.我想使用 powershell 将属性从 10 分钟更改为 5 分钟,并在登录后无限期运行。 How do I specify the SECOND trigger?如何指定 SECOND 触发器?

$Task = Get-ScheduledTask -TaskName "Task" $Task = Get-ScheduledTask -TaskName“任务”

$Task.Triggers.LogonTriggers.Repetition.Duration = "" $Task.Triggers.Repetition.Interval = "PT10M" $Task.Triggers.LogonTriggers.Repetition.Duration = "" $Task.Triggers.Repetition.Interval = "PT10M"

You can modify the $Task object and pass it into the Set-ScheduledTask which will apply the changes you've made.您可以修改 $Task object 并将其传递到 Set-ScheduledTask 中,它将应用您所做的更改。 The first trigger that runs at a specific time will have it's StartBoundary property set, the second trigger which starts at Logon won't have this property set so we'll use the value of that to make sure we change the correct trigger.在特定时间运行的第一个触发器将设置 StartBoundary 属性,第二个在登录时启动的触发器不会设置此属性,因此我们将使用它的值来确保我们更改了正确的触发器。

$Task = Get-ScheduledTask -TaskName "Task"
$RepeatingTrigger = $Task.Triggers | Where-Object { $_.StartBoundary -eq $null }
$RepeatingTrigger.Repetition.Interval = "PT5M"
Set-ScheduledTask -InputObject $Task

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM