Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell 4 Get-ScheduledTask and Windows

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.

like image 835
Andez Avatar asked Oct 30 '14 16:10

Andez


People also ask

How do I get Task Scheduler list in PowerShell?

To retrieve the existing tasks in the task scheduler using PowerShell, we can use the PowerShell command Get-ScheduledTask. We can use the Task Scheduler GUI to retrieve the scheduled tasks. To retrieve using PowerShell, use the Get-ScheduledTask command.

How do I view Scheduled Tasks in Windows?

To open Scheduled Tasks, click Start, click All Programs, point to Accessories, point to System Tools, and then click Scheduled Tasks. Use the Search option to search for "Schedule" and choose "Schedule Task" to open the Task Scheduler. Select the "Task Scheduler Library" to see a list of your Scheduled Tasks.


1 Answers

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)

like image 139
Kohlbrr Avatar answered Oct 17 '22 22:10

Kohlbrr