slowmotion
slowmotion

Reputation: 11

Filter list of scheduled tasks that contain specific string in Task To Run

Actually I need to delete any task that contain some particular string.

I use schtasks /query /v /fo list to list all tasks and schtasks /delete /tn XX /fto remove a specific task.

Right now after I listed all tasks, I have to use Ctrl + F to find the string and copy paste manually.

Is it possible to show only task name that contain specific string in Task To Run? or even I can delete all the related task in one shot.

Thanks.

Upvotes: 0

Views: 847

Answers (1)

user12431753
user12431753

Reputation:

Set TS = CreateObject("Schedule.Service")
TS.Connect("DESKTOP-UCDGI39")

Set rootFolder = TS.GetFolder("\")

Set tasks = rootFolder.GetTasks(0)

If tasks.Count = 0 Then 
    Wscript.Echo "No tasks are registered."
Else
    WScript.Echo "Number of tasks registered: " & tasks.Count

    For Each Task In Tasks
    A=Task.Name
    A = A & " " & Task.NextRunTime
    wscript.echo A
    Next
End If

For more info and sample code https://learn.microsoft.com/en-us/windows/win32/taskschd/displaying-task-names-and-state--scripting-.

Upvotes: 1

Related Questions