January 16th, 2015

PowerTip: Use PowerShell to Delete Scheduled Task

Doctor Scripto
Scripter

Summary: Use Windows PowerShell to delete a scheduled task.

Hey, Scripting Guy! Question How can I use Windows PowerShell to delete a scheduled task?

Hey, Scripting Guy! Answer Use the Unregister-ScheduledTask function. By default, this command will prompt for confirmation. Therefore,
           if you want to use a Windows PowerShell script to remotely delete the scheduled task, you will need to supply
           confirmation in the command. Here is an example:

Unregister-ScheduledTask -TaskName applog -Confirm:$false

Note  This command was introduced in Windows 8 and Windows Server 2012 in the Scheduled Task module,
and it must be run with admin rights.

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

3 comments

Discussion is closed. Login to edit/delete existing comments.

  • Dave Hornbaker

    Is an exception raised if the task does not exist?  I would love to put a try catch around this.

    • Miroslav Mikus

      Yes sir.
      Same problem here. The solution would be:

      $taskName = “The task name”;
      $task = Get-ScheduledTask | Where-Object { $_.TaskName -eq $taskName } | Select-Object -First 1
      if ($null -ne $task) {
      $task | Unregister-ScheduledTask -Confirm:$false
      Write-Host “Task $taskName was removed” -ForegroundColor Yellow
      }

      • Jeremiah Nelsen

        Couldn’t you just verify the task exists before un-registering it?

        if (Get-ScheduledTask -TaskName $TaskName){Unregister-ScheduledTask -TaskName $TaskName -Confirm $false}