We help IT Professionals succeed at work.

Automate powershell in exchange 2010

Is there a way to automate  a powershell command in exchange 2010.

I wanted to find a way to run a powershell command that does exchange health checks and wanted to run it every 2 hours.

this is the command test-exchangeServerHealth.ps1

is there a way to do that?

I was thinking to use the task scheduler, but to run this script the user the user will have to push R to run it.

link to the script


thanks for your help
Watch Question

AntyraelICT Specialist

What you can do to bypass that security prompt is this.
In your Explorer, right-click the script and select Properties.
At the bottom, you will see a security message and an Unblock button.
Click that Unblock button and click Ok, from now on you can run the script without having to answer that security prompt and you can use Task Scheduler to run it automatically.
You can run using Windows Schedule tasks.

1. Create a batch file. Copy the below command and modify where you put your test-exchangeServerHealth.ps1 and save as .bat

powershell -command "&{C:\Temp\Monitoring\test-exchangeServerHealth.ps1}"

Open in new window

2. Create a windows schedule task to run the batch file every 2 hours

As that script has an email option in it you can set up the batch file using the commands below and then add that to your task scheduler.

cd "C:\Scripts\"

powershell -command ./test-exchangeServerHealth.ps1 -Log -SendEmail
AntyraelICT Specialist

I thought the problem was having to push the R key, not making a batch file to run the script in (because that still requires pressing the R key).