With Windows 2008, the task scheduler is setup differently than earlier. You can use the Com object Schedule.Service to access information about tasks.
First we need to get the Com object to talk to the server. This is easily done with a “new object”.
The first line gets you the com object, the second connects to the server. You can put in a server address to query remote servers too.
As 2008 uses task folders, you have to get the folder to search inside. If you don’t organize, this can be “\” or you can use the folder name.
Then get the tasks from that folder.
$tasks is now an array of tasks, which you can walk through, or query. Now we have a task listing, we can figure out the state of each task using a foreach.
The state column is based on the values here. So we know that 4 is running for example.
I used this information to build a script that allowed my Nagios server to manage alerts based on our build server running the build process.