views:

775

answers:

7

Does anyone know of a powershell cmdlet out there for automating task scheduler in XP/2003? If you've ever tried to work w/ schtasks you know it's pretty painful.

+1  A: 

You don't need PowerShell to automate the Task Scheduler, you can use the SCHTASKS command in XP.

According to Wikipedia, the Task Scheduler 2.0 (Vista and Server 2008) is accesible via COM.

PabloG
A: 

Not "native" PowerShell, but if you're running powershell.exe as an administrator then you should have access to the "at" command, which you can use to schedule tasks.

Matt Hamilton
+2  A: 

Ok, Pablo has sparked my interest in saying that the scheduler is accessible via COM.

In PowerShell you can do this:

$svc = new-object -com Schedule.Service

... and that gives you a handle to the task scheduler. You can see what members it has using:

$svc | get-member

One of its methods is NewTask, so I'd start there.

Edit: Some more info here. It's a VBScript example but it'll give you the gist.

Matt Hamilton
A: 

@PabloG Unfortunately, this needs to work on 2003 :( I edited my question to clarify.

slipsec
A: 

This is a good article (be sure to read the other linked article in it) that discusses looking at th scheduled tasks on remote machines. It is not exactly what you were asking for but it should get you headed in the right direction.

EBGreen
A: 

@(EBGreen) Win32_ScheduledJob class only works with at-scheduled jobs.

Windows 2000 and Windows NT 4.0: You can use the Scheduled Tasks UI to modify the task you originally created with WMI. However, although the task is successfully modified, you can no longer access the task using WMI.

The other solution using the com object Schedule.Service is also not an option for 2003

the question is can we use script, PowerShell in particular to retrieve the tasks scheduled using Task Scheduler API? Yes, we can! But you will need Windows Vista to accomplish that.

cheers

slipsec
A: 

@slipsec: I don't have access to a 2003 server to try, but googling "2003 server" SCHTASKS there are links related to questions about it. Perhaps you misspell the command? Like Matt says, you also can use AT, but in this case you don't have access to the scheduled tasks via the Control Panel, only via the AT command.

PabloG