How to delete folder from Task Scheduler with PowerShell?

Question:

I can create a Scheduled Task in Windows using the Register-ScheduledTask PowerShell cmdlet with a particular path (i.e., using -TaskPath “\SomePath\” and -TaskName “SomeName”). I can delete the Task using the Unregister-ScheduledTask with the same parameters. I can verify the deletion with the Windows “Task Scheduler” GUI. However, the folder (“\SomePath\”) does not get deleted. While this makes perfect sense, I cannot find any way to delete this empty folder.

How do I delete an empty Task Scheduler folder using PowerShell?

UPDATE: After more research, I found another way to solve this problem within PowerShell. It involves working with a Schedule.Service object. Here is the code to delete a folder called ‘My Task Folder’:

Answer:

ScheduledTasks are just xml files which are stored here:

You can just delete them from there. They are also referenced from the registry here:

Just use the…

… cmdlet as you normally would for any file or folder.

Now of course, if there is a file/folder attribute set, that is preventing the delete, just remove that.

Source:

How to delete folder from Task Scheduler with PowerShell? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply