How to Delete Scheduled Task with Powershell on Windows

Author: Peter Barnett           Date: May 03, 2019


It is often required to perform periodic scheduled maintenance tasks in automatic mode without human intervention. This can be checking for updates, creating backup copies of critical files, running administrative scripts, etc. For scheduling and automatic execution of tasks in the Windows environment, the standard Task Scheduler tool is provided. The Task Scheduler ensures the execution of pre-prepared tasks at a specific time, or when certain events occur, once or at intervals, in the context of system or user accounts. We can create or delete scheduled task with PowerShell cmdlets, using command line scripts, WSH scripts, or applications.

Unlike previous versions of Windows, Windows Vista, 7, 8, 10 contain an extensive library of pre-configured tasks. These tasks carry out a wide range of operations providing system maintenance and maintaining it in working condition. In addition, the Task Scheduler in these operating systems has become a component necessary for normal operation, which cannot be disabled by standard means.

This is a much more flexible code, Unlike Unregister-ScheduledJob cmdlet , which allows you to access only jobs in a folder: Task Scheduler Library\Microsoft\Windows\PowerShell\ScheduledJobs. That script allows you to delete a task from any folder in Windows Task Scheduler



Firstly Start Windows PowerShell


Click Start, type PowerShell, and then click Windows PowerShell

Step 1 to Delete Scheduled Task with Powershell Cmdlet is to start Powershell



Using Cmdlet to Delete Scheduled Task with Powershell


Cmdlets are specific PS commands that hide a wide variety of functions. The commands built into the interpreter are implemented on the basis of the “verb-noun” principle, for example, Get-Process (obtaining a list of processes). This solution allows you to understand the essence of the team already from its name (in English).

You can create scripts in any text editor (it is better to stop at Win, Notepad ++ or the like, with syntax or verification support) or in PowerShell ISE.

Next, you need to save the following code with the extension ps1 through the File menu.

# create Task Scheduler COM object
$TS = New-Object -ComObject Schedule.Service
# connect to local task scheduler
$TS.Connect($env:COMPUTERNAME)
# get tasks folder (in this case, the root of Task Scheduler Library)
$TaskFolder = $TS.GetFolder("\")
# get tasks in folder
$Tasks = $TaskFolder.GetTasks(1)
# define name of task to delete
$TaskToDelete = "MyTask"
# step through all tasks in the folder
foreach($Task in $Tasks){
if($Task.Name -eq $TaskToDelete){
Write-Host ("Task "+$Task.Name+" will be removed")
$TaskFolder.DeleteTask($Task.Name,0)
}
}

Then you need to run it. This is done in three ways:

  • 1. Write the full path to the script in PowerShell (or ISE)
  • 2. Via the context menu of the ps1 file
  • 3. Open the script in PowerShell ISE and press F


Delete Scheduled Task via Microsoft Management Console Snap-ins


To start mmc.exe, you can use the main menu Control Panel - Administrative Tools - Computer Management - Task Scheduler, or Run (Win + R combination) - taskschd.msc.

open Task Scheduler

In the left part of the main window, lists of tasks are displayed, sorted according to their purpose, in the form of a folder structure. The middle part displays information about the status of tasks and their properties. The right side displays a menu of actions that are valid for tasks.

Delete Scheduled Task with Powershell. Task scheduler interface

In the console tree, locate and select the task folder that contains the task that you want to delete. Then select the task you want to delete in the console window. In the Actions pane, click Delete and confirm Delete dialog box.

Delete task in MMC



Delete Scheduled Task Using Command Line


Open a command prompt window as an administrator: right-click on the "Start" menu and select "Command Prompt (Administrator)";

Open a command prompt as an administrator

Use following command:

schtasks /Delete /

To view help for this command, type:

schtasks /Delete /?




Consider using Action1 to delete scheduled task if:


  • - You need to perform this action on multiple (hundreds or even thousands) computers simultaneously.
  • - You have remote employees with computers not connected to your corporate network at all times.

Action1 is a cloud-based platform for patch management, software deployment, software/hardware inventory, endpoint management and endpoint configuration reporting. It is free with basic functionality.

  

Fully functional free edition for up to 10 endpoints with no expiration date. More details >



Relevant How To Articles and Action1 Features:

By continuing to use our website, you agree with our use of cookies in accordance with our Privacy Policy. You can reject cookies by changing your browser settings.     
Ok, got it