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?
LVL 1
osagaranaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Schnell SolutionsSystems Infrastructure EngineerCommented:
How is configure the execution policy?

Check the result from the command: Get-ExecutionPolicy

If it is using a restricted mode try changing it with Set-ExecutionPolicy unrestricted

It it works, try signing your script and then configure the executionpolicy to its previous state
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
osagaranaAuthor Commented:
Here it is how it is configured:

[PS] C:\Windows\system32>Get-ExecutionPolicy
RemoteSigned
0
Schnell SolutionsSystems Infrastructure EngineerCommented:
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
0
Webinar: What were the top threats in Q2 2018?

Every quarter, the WatchGuard Threat Lab releases an Internet Security Report that describes and analyzes the top threat trends impacting companies around the world. Are you ready to learn more about the top threats of Q2 2018? Register for our Sept. 26th webinar to learn more!

osagaranaAuthor Commented:
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?
0
Schnell SolutionsSystems Infrastructure EngineerCommented:
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
0
osagaranaAuthor Commented:
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}"
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Exchange

From novice to tech pro — start learning today.