How to run Exchange .ps1 script as scheduled task

There are many reasons why one would like to run an Exchange powershell .ps1 script as a scheduled task.

In this post I will share with you how to achieve this on both Microsoft Exchange 2007 and Exchange 2010.

Obviously you should start by creating your .ps1 script for this article we will assume the script location is c:\pcs\YourScript.ps1

The idea is to run the powershell.exe add pass to it the Exchange powershell console as parameter and then finally specify the desired .ps1 script.

You should notice the difference in the path of the Exchange powershell console between Exchange 2007 and Exchange 2010.

Exchange 2007 exshell.psc1 is located at “”C:\Program Files\Microsoft\Exchange Server\Bin\exshell.psc1″”

Exchange 2010 exshell.psc1 is located at “”C:\Program Files\Microsoft\Exchange Server\V14\Bin\exshell.psc1″”

Notice the extra V14 in Exchange 2010 ?

So the full command to run would be

For Exchange 2007

PowerShell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\Bin\ExShell.psc1" -Command ". 'c:\pcs\YourScript.ps1'"

For Exchange 2010

PowerShell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\V14\Bin\ExShell.psc1" -Command ". 'c:\pcs\YourScript.ps1'"

I have been working in IT consultancy and solution integration since 1998 and I consider myself lucky to be, one in a few, making a living out of my passion. I am also member of the famous Experts Exchange (profile here) online community where I try my best to share what I have learned along the road.

Posted in Messaging & Collaboration Tagged with: , , , , ,
4 comments on “How to run Exchange .ps1 script as scheduled task
  1. Kojo says:

    Great !! just what I needed thanks

  2. Alexei Karam says:

    Bravo Toni! Merci 🙂  Merveilleux!

  3. i'm Batman says:

    thank you!

Leave a Reply to i'm Batman Cancel reply

Your email address will not be published. Required fields are marked *

*