Cannot make Exchange PowerShell work as Scheduled Task, why??

I’ve tried a zillion things in the Actions panel and I still get an opcode of 2, supposedly meaning the file can’t be found…AND no events ever get written into the log like they are supposed to be. This is for a scheduled task running ON the Exchange 2010 server.

The parameters line is:

-version 2.0 -NonInteractive -WindowStyle Hidden -command “. ‘C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1’; Connect-ExchangeServer -auto; C:\scripts\Troubleshoot-DatabaseSpace.ps1 -Server e10 -PercentEdbFreeSpaceThreshold 10 -PercentLogFreeSpaceThreshold 10”

I get the same result if I point to this file in the Exchange scripts folder, I copied it from there into C:\scripts.

The action to run is:


The Start In is:


What is wrong with my setup, please???

Scripts permission is RemoteSigned, the script works with all these parameters etc. if I manually run it from a batch file.
I’ve double-checked the presence of each file involved.
This is an Exchange 2010 on Windows Server 2008 R2, all current patches.

Thank you, Tom

What identity is running the task?

It’s being run with the Administrator login (domain admin account, highest privileges, run logged in or not).
The task runs but it doesn’t do what it’s supposed to do, put things into the event log.
Thank you, Tom

That being the case, it’s honestly hard to say without being able to sit in front of it and explore. Have you tried running a very simple script, that perhaps doesn’t use Exchange at all, just to see if you can get ANYTHING to run as a Task?

I’ll try using another simple Exchange script…
I had similar problems with a login monitoring script…and gave up.
But now I really need to figure out doing something like this. :slight_smile:
Thank you, Tom

Does the host where the script resides have the same EMS as the Exchange servers? Some commands won’t run even if you include a ‘load snapin’ command : Add-PSSnapin Microsoft.Exchange.Management.Powershell.E2010
Been caught out with this before!

The scheduled task IS running ON the Exchange 2010 server. As administrator.
I have not had opportunity to work on this b/c of putting out fires…
Thank you, Tom

I had similar problems…

Running this from my exchange server’s Task Scheduler works great:

Program/Script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Add arguments: -command “. ‘D:\Program Files\Microsoft\Exchange Server\V15\Bin\RemoteExchange.ps1’; Connect-ExchangeServer -auto; c:\scripts\sep_attack.ps1”

Have you tried removing ’ -Server e10 -PercentEdbFreeSpaceThreshold 10 -PercentLogFreeSpaceThreshold 10’ and seeing if it works? Maybe just add a read-host at the end of your script to see what its doing?

One is required to put the -server parameter so the script knows which server to work on.
I think I tried removing the other params.
It will be a couple weeks before I can get back to this.
Thank you, Tom

Are you tried to run your command from cmd and not task scheduler?
Fine if cmd will be executed from the same user as in task scheduler

runas /user:domain\requireuser cmd
>powershell -command …

and when you see that it executed exactly as you need and produce output you need, just copy/paste latest command to scheduler