Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a couple of Exchange 2010 PowerShell scripts that I'd like to run as Scheduled Tasks.

If I launch PowerShell using "Run as different user" I can run the scripts and they execute correctly.

If I schedule a task using that same user, the task stays in the Running state forever.

How can I figure out where the task is getting stuck?

For reference, here's how I enable the Exchange stuff:

. 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'
Connect-ExchangeServer -auto

And here is the ways I have tried to run the script from the Task Scheduler:

  • powershell -command "& {. 'c:\windows\script.ps1' }"
  • powershell -file 'c:\windows\script.ps1'
  • powershell -file "c:\windows\script.ps1"

All with the same result. Grr...

share|improve this question

2 Answers 2

Not sure if this is how you are doing it, but when I am running PowerShell scripts via task scheduler I use the "Start a program" action and select powershell and then add the arguments from there. That might be what you are doing here, but it's kind of unclear. Here's a screenshot: enter image description here

Per TheCompWiz execution policy might also be an issue.

share|improve this answer
That's not even valid command line syntax for powershell.exe, but just for the heck of it I tried it. The task immediately failed. –  longneck Nov 1 '12 at 18:20
Interesting because all of my daily powershell tasks run that way and they function just fine. –  ZnewmaN Nov 1 '12 at 20:21
C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -command "& 'c:\windows\script.ps1' " –  ZnewmaN Nov 1 '12 at 20:24
ah, there's the difference. your screenshot doesn't show the -command –  longneck Nov 1 '12 at 20:44
Yeah, I actually personally don't use -command, but it is probably the proper use. –  ZnewmaN Nov 1 '12 at 20:52

You either need to modify your execution policy, or specify the -ExecutionPolicy Bypass as a commandline parameter.

powershell -Command "<path to .ps1 script>" -ExecutionPolicy Bypass
share|improve this answer
I added the ExecutionPolicy option to my command line parameters. No change; task still runs forever. –  longneck Nov 1 '12 at 18:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.