1

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"

  • 1
    If your tasks really depend on local time, then run the server on local time. – Michael Hampton Feb 17 '13 at 19:00
  • @MichaelHampton Some tasks do, some don't. I certainly don't want to run my server on local time, since events which need to happen at 2am don't need to happen twice when the time changes. – Cade Roux Feb 17 '13 at 21:30
2

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.

  • Not so weird - this is a VB level array, they always started with 1. – TomTom Feb 17 '13 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.