Link to home
Start Free TrialLog in
Avatar of osagarana
osagarana

asked on

Run Exchange Powershell cmdlt from Task Scheduler does not work

Environment:
Exchange 2010 SP2
MS Windows Server 2008 R2

Hi Experts,

I am having a hard time to run my Exchange command from task scheduler and now I am running out of ideas.
The command is simple: Get-ClientAccessServer | Update-FileDistributionServer -Type OAB

Everything runs perfectly when I run this command from Exchange Shell.

So I tried to set a Task Scheduler to run this command.

Program/script: powershell.exe
Add arguments (optional): -version 2.0 -NonInteractive -WindowStyle Hidden -executionpolicy bypass -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; &{Get-ClientAccessServer | Update-FileDistributionService -Type OAB}"

It does not work. I already tried everything. I using the administrator user to create this task. I suspect it can be lack of permissions from task scheduler. I do not know.

Any ideas?
ASKER CERTIFIED SOLUTION
Avatar of Ogandos
Ogandos
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of osagarana
osagarana

ASKER

Here it is how it is configured:

[PS] C:\Windows\system32>Get-ExecutionPolicy
RemoteSigned
First of all try changing it with the CMDLet Set-ExecutionPolicy unrestricted and lets check if it returns the same error

You can configure the parameter back with Set-ExecutionPolicy RemoteSigned
It started to work. But I tested on my lab.    :-)
I need to test on the production which is set to RemoteSigned.

Is there a way to bypass this execution policy?
You can sign your script, at this website they explain how can you make it: http://www.mikepfeiffer.net/2010/02/obtaining-a-code-signing-certificate-and-signing-powershell-scripts/

Another option is just configure your execution policy to unrestricted like you did. But it is less secure as far as the system won't validate any kind of script sign before executing
I tested with this argument and it worked:
-version 2.0 -NonInteractive -WindowStyle Hidden -executionpolicy unrestricted -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; &{Get-ClientAccessServer | Update-FileDistributionService -Type OAB}"