[英]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) : 我正在使用schtask在Powershell 3(Win7)中运行计划任务:
$taskname = "task"
schtasks /Run /Tn $taskname
Now, I'm trying to do the same thing with Schedule.service : 现在,我正在尝试使用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 此任务已经配置,仅需要启动
You can run the task with the .Run()
method passing a null: 您可以通过传递空值的.Run()
方法来运行任务:
$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. 我还没有找到文档参考,所以我不确定该参数指定了什么,但是我会在找到它时更新答案,或者如果有人在我之前找到它,也欢迎其他人这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.