PowerShellPack - TaskScheduler module - run task with no logged user
Asked Answered
E

1

3

I need to schedule a task via Powershell v2 on Windows Server 2008. I am using the TaskScheduler module from the MS PowershellPack.

Scheduling a task is ok, but I need the task to run even nobody is logged on. I saw that this is possible in Powershell v3 on Win8 or Win2k12 (this QA). But that is not my case - I need to this in Powershell version 2.

Is this possible with module I am using? Or is there some workaround?

Eugine answered 3/3, 2014 at 16:12 Comment(2)
Are you running Windows Server 2008 or Windows Server 2008 R2? If you are running Windows Server 2008 R2, you can install .NET Framework 4.5.1 and then Windows Management Framework Core 4.0 to get PowerShell v4.0.Hygrograph
Win2k8 R2. Unfortunately v3 or v4 is not a choice for us because we are working with Sharepoint 2010, so all of our powershell have to stay v2.0 (Powershell ISE is not compatible...)Eugine
C
5

http://msdn.microsoft.com/en-us/library/windows/desktop/bb736357(v=vs.85).aspx

Not possible down in the V2 world, But this will accomplish everything you need, and can be directly called from powershell

Edit:

This question got me thinking, and I realized your scenario is slightly different than mine, making it so this Should Be Possible.. So I was wrong before. Turns out, the Scheduler.service comobject is compatible with Powershell 2.0, but also only works with Task Scheduler 2.0. I thought it wasn't because I am on xp, and Task Scheduler 2.0 is only available in vista and up.

Looking into the source code of that MS PowershellPack, I found that all it is doing is using the Scheduler.service com object. https://github.com/sushihangover/SushiHangover-PowerShell/tree/master/modules/TaskScheduler

For a good tutorial of how to manipulate this com object for yourself : https://blogs.technet.microsoft.com/heyscriptingguy/2009/04/01/hey-scripting-guy-how-can-i-best-work-with-task-scheduler/

And the answer to your question: How to set schedule.service "Run whether user is logged on or not" in Powershell?

Sorry for the misunderstanding.. I won't let it happen again :D
Either way the schtasks.exe will cover all your bases and IMO is easier to work with, because it is one command, and doesnt require you to Invoke-Session when trying to schedule a task on a remote server.

Culley answered 3/3, 2014 at 16:14 Comment(4)
It's always a little sad when those correct and accepted answers are also those "no, that will not work"...Eugine
True, the limitations of the windows xp and V2 world is sad. But it should all be going away soonCulley
Just to provide "linked QA" for the schtasks.exe solution - #11190905Eugine
@Eugine Hope my update didn't come to late, Turns out it will work. My badCulley

© 2022 - 2024 — McMap. All rights reserved.