I needed a script to find out the status of Windows Task Scheduler. If one has a problem, to echo it out as a problem and exit on an error code

 

‘———————————————————
‘ This sample enumerates through the tasks on the local computer and
‘ displays their name and state.
‘———————————————————
dim strerrors

‘ Create the TaskService object.
Set service = CreateObject(“Schedule.Service”)
call service.Connect()

 

‘ Get the task folder that contains the tasks.
Dim rootFolder
Set rootFolder = service.GetFolder(“\”)

Dim taskCollection
Set taskCollection = rootFolder.GetTasks(0)

Dim numberOfTasks
numberOfTasks = taskCollection.Count

If numberOfTasks = 0 Then
Wscript.Echo “No tasks are registered.”
Else
WScript.Echo “Number of tasks registered: ” & numberOfTasks

Dim registeredTask
For Each registeredTask In taskCollection

if registeredTask.LastTaskResult = 0 then

wscript.echo “Task Name: ” & registeredTask.Name & ” is all ok”
else
wscript.echo “Task Name: ” & registeredTask.Name & ” has Problems”

strerrors = “1”
end if
Next
end if

if strerrors = “1” then
wscript.echo “You have problems”
WScript.Quit(1001)

else
wscript.echo “All OK”
WScript.Quit(0)
end if

As always this blog break the speak marks, so remember to find and replace all ” and ” in notepad to fix it up.

 

TaskSchedule Lookup.vbs

 

« »