Reputation: 43
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. 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. How do I specify the SECOND trigger?
$Task = Get-ScheduledTask -TaskName "Task"
$Task.Triggers.LogonTriggers.Repetition.Duration = "" $Task.Triggers.Repetition.Interval = "PT10M"
Upvotes: 2
Views: 2643
Reputation: 1469
You can modify the $Task object and pass it into the Set-ScheduledTask which will apply the changes you've made. 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.
$Task = Get-ScheduledTask -TaskName "Task"
$RepeatingTrigger = $Task.Triggers | Where-Object { $_.StartBoundary -eq $null }
$RepeatingTrigger.Repetition.Interval = "PT5M"
Set-ScheduledTask -InputObject $Task
Upvotes: 2