• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 638
  • Last Modified:

Run Exchange Powershell cmdlt from Task Scheduler does not work

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?
  • 3
  • 3
1 Solution
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
osagaranaAuthor Commented:
Here it is how it is configured:

[PS] C:\Windows\system32>Get-ExecutionPolicy
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
We Need Your Input!

WatchGuard is currently running a beta program for our new macOS Host Sensor for our Threat Detection and Response service. We're looking for more macOS users to help provide insight and feedback to help us make the product even better. Please sign up for our beta program today!

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?
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
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}"
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now