Powershell 4 Get-ScheduledTask and Windows

北城余情 提交于 2020-01-03 08:43:12

问题


I thought no matter what OS you had, if you had Powershell installed, you would have access to the same default cmdlets.

So I want to use Get-ScheduledTask on my Windows 7 machine. I have Powershell 4 installed. However, when I run it, I get the error:

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

If I run on my Windows 8.1 with Powershell 4 already pre-installed along with the OS, it works.

Can I get the cmdlets on my Windows 7 machine? There is nothing on the Microsoft Get-ScheduledTask page about Windows 7 so I am guessing not.

If not then would it be a case of using the command line:

scheduled task command line

No doubt someone will point me at this question but that was for Powershell 2. I am on Powershell 4.

Now I am a big fan of not reinventing the wheel, but this guys scripts look a good alternative.


回答1:


Get-ScheduledTask relies on underlying features of the OS that Windows 7 doesn't have, so there is no way to run the cmdlet on that OS, even with PowerShell v4. In your case, you can either leverage schtasks.exe or the Schedule.Service COM object.

This answer that you linked gives the best overview of these methods, but in the interests of completeness, I'll link the relevant resources here:

schtasks.exe

MS PowerShellPack TaskScheduler module -> (leverages the Schedule.Service COM object)



来源:https://stackoverflow.com/questions/26658249/powershell-4-get-scheduledtask-and-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!