Home » PowerShell » PowerShell Disable Scheduled Task on Remote Computer

PowerShell Disable Scheduled Task on Remote Computer

Use the PowerShell command `Disable-ScheduledTask` with the `CimSession` object that contains the remote computer connection to disable scheduled tasks on a remote computer.

The Disable-ScheduledTask cmdlet disables the scheduled task. Disabling a task prevents it from running even if is scheduled to run. The CimSession object contains information about a remote computer connection.

In this article, we will discuss how to disable scheduled tasks on the remote computer, and disable scheduled tasks in the root folder on the remote computer.

Disable Remote Scheduled Tasks in PowerShell

Using the PowerShell script, the Disable-ScheduledTask cmdlet disables the scheduled tasks remotely. It takes the CimSession object that contains the remote computer connection information.

# Create remote computer connection using New-CimSession
$session = New-CimSession -ComputerName "corpit-euc-101"

# Disable the scheduled tasks on remote computer

Disable-ScheduledTask -CimSession $session -TaskName "Adobe Acrobat Update Task"
 

In the above PowerShell script, the New-CimSession cmdlet creates a new connection with the remote computer specified using the ComputerName property and stores the connection details in the $session CimSession object.

The Disable-ScheduledTask cmdlet uses the CimSession object to connect to a remote computer and disable scheduled tasks where TaskName is equal to the specified name.

The output of the above PowerShell script to disable a scheduled task on a remote computer is:

PS C:\> $session = New-CimSession -ComputerName "corpit-euc-101"   
  
PS C:\> Disable-ScheduledTask -CimSession $session -TaskName "Adobe Acrobat Update Task"
                                
TaskPath    TaskName                                       State          PSComputerName
--------           --------                                                -----             --------------
\                   Adobe Acrobat Update Task         Disabled   corpit-euc-101

Disabling a scheduled task prevents the task from running even if the scheduled to run so. To run the scheduled task again, enable the scheduled task on the remote computer.

Another way to disable a scheduled task is to get the list of scheduled tasks remotely using the Get-ScheduledTask command, use the Where clause to filter the required task name, and use the Disable-ScheduledTask command to disable a scheduled task remotely.

$session = New-CimSession -ComputerName "corpit-euc-101

Get-ScheduledTask -CimSession $session | Where {$_.TaskName -like "Adobe*"} | Disable-ScheduledTask

The output of the above command disables a scheduled task remotely.

PowerShell Disable Scheduled Task on Remote Computer
PowerShell Disable Scheduled Task on Remote Computer

PowerShell Disable Scheduled Task in Folder Remotely

Use the Disable-ScheduledTask cmdlet in PowerShell to disable all scheduled tasks in a folder retrieved using the Get-ScheduledTask command.

$session = New-CimSession -ComputerName "corpit-euc-101
Get-ScheduledTask -CimSession $session -TaskPath "\Mozila\" | Disable-ScheduledTask

In the above PowerShell script, the New-CimSession cmdlet creates a new connection with a remote computer and stores the connection details in the CimSession object $session.

The Get-ScheduledTask command uses the CimSession parameter to connect to a remote computer and list all the scheduled tasks in a folder specified by the TaskPath parameter. It pipes the information to the Disable-ScheduledTask cmdlet which disabled all scheduled tasks in a folder.

Conclusion

I hope the above article on how to disable scheduled tasks on a remote computer using the PowerShell command Disable-ScheduledTask is helpful to you.

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