7

我认为无论您使用什么操作系统,如果您安装了 Powershell,您都可以访问相同的默认 cmdlet。

所以我想在我的 Windows 7 机器上使用Get-ScheduledTask 。我安装了 Powershell 4。但是,当我运行它时,我得到了错误:

Get-ScheduledTask : The term 'Get-ScheduledTask' is not recognized as the name 
of a cmdlet, function, script file, or operable program. Check the spelling of 
the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Get-ScheduledTask
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-ScheduledTask:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

如果我在我的 Windows 8.1 上运行,并且已经与操作系统一起预装了 Powershell 4,它就可以工作。

我可以在我的 Windows 7 机器上获取 cmdlet 吗?Microsoft Get-ScheduledTask 页面上没有关于 Windows 7 的内容,所以我猜不是。

如果不是,那么是否是使用命令行的情况:

计划任务命令行

毫无疑问,有人会指出我这个问题,但那是针对 Powershell 2 的。我在 Powershell 4 上。

现在我非常喜欢不重新发明轮子,但是这些家伙的脚本看起来是一个不错的选择。

4

1 回答 1

6

Get-ScheduledTask依赖于 Windows 7 没有的操作系​​统的底层功能,因此即使使用 PowerShell v4,也无法在该操作系统上运行 cmdlet。在您的情况下,您可以利用schtasks.exeSchedule.ServiceCOM 对象。

您链接的这个答案提供了这些方法的最佳概述,但为了完整起见,我将在此处链接相关资源:

schtasks.exe

MS PowerShellPack TaskScheduler 模块->(利用Schedule.ServiceCOM 对象)

于 2014-11-07T00:55:04.917 回答