Score:1

How to delete a Scheduled task folder with PowerShell?

cn flag

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?

cn flag
It looks like deleting the registry key here would work: `HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\PathToFolder`
bjoster avatar
cn flag
This is short, hard ... and works.
Score:2
cn flag

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

Bernd Schwanenmeister avatar
au flag
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 <code> for /f "tokens=1" %%a in ('schtasks /tn \test\ ^|findstr /v "TaskName ==== Folder"') do schtasks /delete /tn \test\%%a /f</code>
Swisstone avatar
cn flag
@BerndSchwanenmeister Powershell equivalent: `Get-ScheduledTask | where TaskPath -eq "\MyPath\" | Unregister-ScheduledTask -Confirm:$false`
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.