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?

Community
  • 1
  • 1
jumbo
  • 4,670
  • 5
  • 39
  • 44
  • 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. –  Mar 03 '14 at 16:53
  • 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...) – jumbo Mar 03 '14 at 19:57

1 Answers1

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.

SamB
  • 9,039
  • 5
  • 49
  • 56
Cole9350
  • 5,444
  • 2
  • 34
  • 50
  • It's always a little sad when those correct and accepted answers are also those "no, that will not work"... – jumbo Mar 04 '14 at 07:40
  • True, the limitations of the windows xp and V2 world is sad. But it should all be going away soon – Cole9350 Mar 04 '14 at 14:26
  • Just to provide "linked QA" for the schtasks.exe solution - http://stackoverflow.com/questions/11190405/how-to-schedule-a-task-wether-the-user-is-logged-on-or-not-in-powershell – jumbo Mar 04 '14 at 21:30
  • @jumbo Hope my update didn't come to late, Turns out it will work. My bad – Cole9350 Mar 06 '14 at 17:57