Running Exchange PowerShell as Scheduled Task

2017-12-08T16:23:40+00:00 December 1st, 2011|Exchange|

If you want to run any of the Exchange PowerShell commands from a standard PowerShell environment then you simply need to add in the following line in order to run it as if it is an Exchange Management Console:

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010

For example, the script below will output the size of the Exchange Databases to a file and can be run as a scheduled task:

 

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010

Get-MailboxDatabase –Status | fl name, databasesize | out-file C:dbsize.txt

 

What we can do then is save the above script to a .ps1 file and then edit the action to start PowerShell.exe and put the arguments as the script that you want to run:

image

This can be set up with the usual Scheduled Task settings and with the PowerShell snap-in for Exchange added in should be able to use the Exchange PowerShell commands.

Cheers

Paul