Schedule PowerShell Exchange script
Sometimes you might need to schedule PowerShell Exchange script using the Windows Task Scheduler. In this post, I will walk you through how to perform this task. You need to make sure you have Exchange PowerShell installed on the machine where the script will be run. If you are an Exchange administrator, then you should browse the internet for Exchange script, as there are many amazing scripts out there that can help you better manager and monitor your Exchange installation.
- Open the Task Scheduler in Windows > Task Scheduler Library > right click and “Create Basic Task..“
- Type a descriptive name for your task and click Next.
- On the Trigger section, choose your schedule that fits your needs.
- On the Action, choose “Start a program“, Click Next.
- On the “Start a Program” subsection, Enter:
- In the Program/Script, type C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
- In the Add Arguments (Optional) ,type
-command ". 'c:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; D:\Myscript.PS1
- In the Start in (Optional), leave it empty
Note: Replace D:\Myscript.PS1 with your script path.
Note: Make sure the machine has Exchange PowerShell Management Tools installed already.
I hope by now you know how to schedule PowerShell Exchange script using the Windows Task Manager. As you can see, it is an easy thing to do. I will also leave you with a quick top when doing so.
I have discovered in a hard way, that you will get problem, and the script will not run, if the path length to your script is too long. For example, it is not good idea to host your script under deep folder structure like D:\Path1\path2\path3\path3 management scripts for Exchange that i love to schedule\Script Directory\Cool Scripts\Myscript.PS1
This is a long path, and there is a limit for the length of commands in the Windows Task Scheduler. Keep that in mind.