Home Β» PowerShell Β» PowerShell Script to Disable Scheduled Task

PowerShell Script to Disable Scheduled Task

The command to disable scheduled tasks in the PowerShell is Disable-ScheduledTask. This command uses the TaskName or TaskPath to disable one or more scheduled tasks in PowerShell.

Disable-ScheduledTask cmdlet in PowerShell disables a scheduled task. This command requires administrator privileges or elevated permission to disable tasks else throw an exception "Disable-ScheduledTask: Access is denied."

In this article, we will discuss how to disable scheduled tasks, query scheduled tasks by name, and disable them using a PowerShell script.

PowerShell Script to Disable Schedule Task in Windows

Use the Disable-ScheduledTask cmdlet in Powershell to disable scheduled tasks in the Windows operating system.

Disable-ScheduledTask -TaskName "UserAccountTests" 

In the above PowerShell script, the Disable-ScheduledTask cmdlet uses the TaskName parameter to specify the scheduled task name and disable the task in the root folder. It updates the State property of the task to Disabled

The output of the above PowerShell script after disabling a scheduled task with PowerShell is:

Disable Scheduled Task using PowerShell
Disable Scheduled Tasks using PowerShell

Disable Scheduled Task Located in Root using PowerShell

Scheduled tasks are located in the root as well as the custom folders. To disable the scheduled tasks located in the Root folder use the following PowerShell script.

Get-ScheduledTask -TaskPath "\" | Disable-ScheduledTask

The Get-ScheduledTask cmdlet gets all the scheduled tasks located in the root folder using the TaskPath parameter and pipes them to the Disable-ScheduledTask command to disable all scheduled tasks in the root folder.

How to Query Scheduled Tasks by Name and Disable

Use the Get-ScheduledTask command in PowerShell to query the scheduled task by tas name and pipes the information to the Disable-ScheduledTask cmdlet to disable it.

 Get-ScheduledTask | Where {$_.TaskName -eq "UserAccountTests"} | Disable-ScheduledTask

The Get-ScheduledTask command retrieves all the tasks and pipes the information to the Where command to check TaskName is equal to provided task name using the -eq operator and pipes the scheduled task to the Disable-ScheduledTask command to disable it.

The output of the above PowerShell script to find the scheduled task by name and disable it is:

Search Scheduled Tasks by Name and Disable
Search Scheduled Tasks by Name and Disable

Check if Scheduled Task is Disabled in PowerShell

Use the command Get-ScheduledTask to check if the scheduled task is disabled or not. This command has State property that has value "Disabled” if the task is disabled. If the task is enabled, it has the value β€œReady” and Running if the task is in the running state.

Get-ScheduledTask | Where {$_.TaskName -eq "UserAccountTests"} | Select State

The Get-ScheduledTask command retrieves all tasks and pipes the information to the Where clause to check for a specific task state. It returns the scheduled task state.

The output of the above PowerShell script returns the task state as β€œDisableβ€œ, this means a scheduled task is disabled.

PS C:\> Get-ScheduledTask | Where {$_.TaskName -eq "UserAccountTests"} | Select State                                       
   State
   -----
Disabled

The scheduled task state is disabled hence there is no need to use the Disable-ScheduledTask command.

PowerShell Disable Scheduled Task Access Denied

While trying to disable a scheduled task with the PowerShell terminal, if it throws an exception β€œDisable-ScheduledTask: Access is denied.β€œ, this means that the user doesn’t have enough privileges to execute the command.

Disable-ScheduledTask - Permission Denied Error
Disable-ScheduledTask – Permission Denied Error

To fix the access denied issue, run the PowerShell terminal with β€œRun as administrator” privileges or the user having elevated permissions to execute the command.

Conclusion

I hope the above article on how to use Powershell script to disable scheduled tasks in the Windows operating system is helpful to you.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.