简体   繁体   English

我如何使用powershell和schedule.service运行计划的任务

[英]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.

相关问题 如何在PowerShell v3中使用ComObject Schedule.service创建计划任务? - How can I create a scheduled task with ComObject Schedule.service in PowerShell v3? 如何从Powershell中的Schedule.Service获取文件夹列表 - How to get list of folders from Schedule.Service in powershell Powershell - 创建计划任务以作为本地系统/服务运行 - Powershell - Create Scheduled Task to run as local system / service Powershell:将计划任务创建到计划任务文件夹中; 找不到路径 - Powershell: Create a Schedule Task into a Scheduled Task Folder; Path not found 如何运行计划任务以提升权限停止和启动SSRS服务? - How to run a scheduled task to stop and start SSRS service with elevated permissions? 如何让Powerershell在计划任务中执行? - How do I get Powershell to execute in scheduled task? 如何使用 PowerShell 为计划任务定义到期日期 - How can I define an expiry date to a scheduled task using PowerShell Powershell 脚本来查找/运行计划任务或创建 - Powershell Script To Find/Run Scheduled Task or Create 计划任务 PowerShell 或 CMD 脚本 - “以管理员身份运行” - Scheduled Task PowerShell or CMD script - “Run As Administrator” PowerShell 脚本将手动运行,但不会按计划任务运行 - PowerShell script will run manually but not as scheduled task
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM