Manipulating Scheduled Tasks

by Mar 20, 2013

If you need to change and adjust settings in a registered scheduled task, there is a COM interface called 'Schedule.Service' that you can use to access all registered scheduled tasks (Vista/Server 2008 or better).

The sample code below accesses the scheduled task "RACTask" in the folder "\Microsoft\Windows\RAC" and makes sure the trigger "RACTimeTrigger" is enabled. You will need Administrator privileges to change tasks.

$service = New-Object -ComObject("Schedule.Service")
$service.Connect($env:COMPUTERNAME)
$folder = $service.GetFolder('\Microsoft\Windows\RAC')
$task = $folder.GetTask('RACTask')
$def = $task.Definition
$def.triggers | Where-Object { $_.ID -eq 'RACTimeTrigger' } | ForEach-Object { $_.Enabled = $true }
$folder.RegisterTaskDefinition($task.Name, $def, 4, $null, $null, $null)

Beginning with Windows 8 / Server 2012, there is finally a module devoted to scheduled task management. This is how you can list the cmdlets available:

PS> Get-Command -Module ScheduledTasks

The new module "ScheduledTasks" is great but won't help you if you run scripts on older Windows versions.

Twitter This Tip! ReTweet this Tip!