Toggling enabled/disabled on specific triggers in a task in the task scheduler using powershell (or something else)
Related to this question:
Windows Server in UTC, need Task Scheduler to shift tasks with summer time
and this question:
https://stackoverflow.com/questions/11458029/enabling-disabling-tasks-in-task-scheduler-using-a-powershell-script
Is there a way to selectively enable and disable certain triggers (not the whole task) with powershell?
I have two "Daily" triggers on my task on my UTC server, one scheduled to run an hour after the other. I only want one to be enabled, and I want to toggle between them twice a year.
The Task Scheduler doesn't appear to have a unique "name" for the triggers, they just appear as "Daily"
Solution 1:
There are lots of ways to interface with Task Scheduler. For example, you can use the Schedule.Service COM object.
$TaskScheduler = New-Object -COMObject Schedule.Service
$TaskScheduler.Connect()
$TaskFolder = $TaskScheduler.GetFolder("\") # If your task is in the root "folder"
$Task = $TaskFolder.GetTask("The Name Of Your Task")
$Triggers = $Task.Definition.Triggers
$FirstTrigger = $Triggers.Item(1)
Those trigger objects each have an Enabled property. I think the array indices here start at 1, which is weird, but whatever.
Edit: And oh yeah, the RegisterTaskDefinition() method should save your changes.