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?
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.