Disable/Enable Scheduled tasks using Powershell and COMObject

Disable/Enable Scheduled tasks using Powershell and COMObject

December 11, 2018 0 By Amir Joseph Sayes

While working on a project for a client where many of the Windows Systems are 2008R2 with PowerShell 3.0 or lower, there was a need to automate disabling scheduled tasks to ensure consistency across the XenApp/XenDesktop estate.

This is something that can be done easily in PowerShell 4.0+ using Get-scheduledTask cmdlet. But in PowerShall 3.0 and earlier, it gets a bit trickier.

Based on the script by Jaap Brasser where he enumerates all tasks subfolders, I have written a new code which can accept an array of schedule tasks names, along with a switch to enable/disable them.

How to use

  1. Add the below two functions in your PowerShell session on the system where the tasks should be disabled.
  2. Call the  Set-TaskStatus function and pass the status (Enabled, Disabled) and the tasks names (Array)

Example

The output will be something like this

PS_Scheduledtasks

The Script