1

I have several windows schedule tasks running on my windows 2003 server and some time one of those tasks is hunged for some reason and the status keeps on "running".. what Im looking for is some basic script to "get a list of all RUNNING jobs on server XXXXXX for more than XX minutes."

Some help?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Santos
  • 177
  • 1
  • 1
  • 15

3 Answers3

2

You have to use schtasks /query instead. Win2k3 has no Schedule.Service COM object. It is a part of Win2k8\Win7 only.

nightwind
  • 21
  • 2
1

Try this:

$servername = "localhost"
$schedule = new-object -com("Schedule.Service") 
$schedule.connect($servername) 
$tasks = $schedule.getfolder("\").gettasks(0)
$tasks | Where-Object {$_.State -eq 4} |select name, lastruntime

This will return you all the running tasks and time they were started

Andrey Marchuk
  • 13,301
  • 2
  • 36
  • 52
  • Thanks... I will try it and let you know. – Santos Mar 15 '12 at 15:23
  • I get this:New-Object : Cannot load COM type Schedule.Service. At line:2 char:23 + $schedule = new-object <<<< -com("Schedule.Service") + CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException + FullyQualifiedErrorId : CannotLoadComObjectType,Microsoft.PowerShell.Commands.NewObjectCommand – Santos Mar 15 '12 at 15:27
  • I confirm that I hace Windows 2003 R2 Server enterprise Ed. SP2 – Santos Mar 15 '12 at 15:29
  • According to this... I have version 2.0 – Santos Mar 15 '12 at 15:38
  • I tried that line only and get the same result. I see the TASK SCHEDULER service started.. actually all task work OK. May be some piece that I need to install or add to powershell? – Santos Mar 15 '12 at 15:41
  • No, I don't have any extensions. It's just COM object that is always there since long time ago. Can you cath exception and see what the inner exception is? – Andrey Marchuk Mar 15 '12 at 15:44
  • mmm Im afraid that I dont know how to do that. – Santos Mar 15 '12 at 15:49
0

try $SchedService = new-object -ComObject Schedule.Service

Peter DeWeese
  • 18,141
  • 8
  • 79
  • 101