I wrote up a pretty cool advanced function that will delete individual scheduled tasks, but what if someone wants to just delete all scheduled tasks within a parent folder rather than have to name each one? For instance, here is a script I found online that deletes individual tasks:
# create Task Scheduler COM object
$TS = New-Object -ComObject Schedule.Service
# connect to local task sceduler
$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)
}
}
So how would we tell the DeletTask method to just delete all of the tasks within a task folder rather than having to define each one? Is there a wild card (i.e. the asterisk *) I can use that I am not aware of?
Thanks