mrplume
mrplume

Reputation: 183

How I could run a scheduled task with powershell and schedule.service

I'm using schtask for running a scheduled task in a Powershell 3 (Win7) :

$taskname = "task"
schtasks /Run /Tn $taskname

Now, I'm trying to do the same thing with Schedule.service :

$ProductName ="task"
$ScheduledTaskService=new-object -com("Schedule.Service") 
$ScheduledTaskService.connect() 
$ScheduledTaskToRun=$ScheduledTaskservice.GetFolder("\").GetTasks(0)|Where-Object{($_.Name -eq $ProductName)}

But at this point, I don't know what I need to do for running the task. This task is already configurated and need only to be launch

Upvotes: 0

Views: 1829

Answers (1)

Tony Hinkle
Tony Hinkle

Reputation: 4742

You can run the task with the .Run() method passing a null:

$ScheduledTaskToRun.Run($null)

I haven't found the documentation reference yet, so I'm not sure what the parameter specifies, but I'll update the answer when I find it, or someone else is welcome to do it if they find it before I do.

Upvotes: 2

Related Questions