1

I need to delete a scheduled task folders on a lot of machines, ideally with PowerShell. I couldn't find anything on how to do that - it seems like the documentation covers everyting but folders.

Did I miss someting?

bjoster
  • 4,805
  • 5
  • 25
  • 33

1 Answers1

3

Looks like you can't do that with the Task Scheduler cmdlet.

However, someone posted the solution on StackOverflow: How to delete folder from Task Scheduler with PowerShell? :

$scheduleObject = New-Object -ComObject Schedule.Service
$scheduleObject.connect()
$rootFolder = $scheduleObject.GetFolder("\")
$rootFolder.DeleteFolder("My Task Folder",$null)

The documentation about DeleteFolder is available here:

https://docs.microsoft.com/en-us/windows/win32/taskschd/taskfolder-deletefolder

Swisstone
  • 6,725
  • 7
  • 22
  • 32
  • 1
    Yes, that works. But before it does, the task folder needs to be emptied. And that again needs some syntax I am not aware of. In batch, to delete all tasks in a folder "test", I would use for /f "tokens=1" %%a in ('schtasks /tn \test\ ^|findstr /v "TaskName ==== Folder"') do schtasks /delete /tn \test\%%a /f – Bernd Schwanenmeister May 19 '22 at 07:57
  • @BerndSchwanenmeister Powershell equivalent: `Get-ScheduledTask | where TaskPath -eq "\MyPath\" | Unregister-ScheduledTask -Confirm:$false` – Swisstone May 20 '22 at 19:23