Creating Scheduled Tasks for Exchange 2010 PowerShell Scripts

EXCHANGE How To KB MS Powershell

Creating Scheduled Tasks for Exchange 2010 PowerShell Scripts

PowerShell Command Syntax for Scheduling Tasks on a Machine with the Exchange 2010 Management Tools Installed

The following command syntax is what you’ll want to use to schedule your task. You need to tell PowerShell to load the Exchange Management Shell environment before executing your script. This will give you access to all of the cmdlets, variables and functions that are loaded with Exchange Management Shell. To schedule a .ps1 script to move mailboxes, the syntax would look something like this:
C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -command “. ‘C:Program FilesMicrosoftExchange ServerV14binRemoteExchange.ps1′; Connect-ExchangeServer -auto; c:ScriptsMoveMailboxes.ps1

PowerShell Command Syntax for Scheduling Tasks on a Machine Without the Exchange Management Tools Installed

To schedule PowerShell scripts we don’t actually need the Exchange tools installed, all we need is PowerShell v2. We can use implicit remoting to import the Exchange Management Shell cmdlets from a specific server. Take a look at the syntax:

C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -command “$s = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://fab-ex2.fabrikam.local/PowerShell/ -Authentication Kerberos ; Import-PSSession $s ; Get-Mailbox -Database DB1 | New-MoveRequest -TargetDatabase DB2″

You can paste the code in schedule task as below:

 Note – please change input values (marked in yellow) as per your requirements. 


(Visited 3 times, 1 visits today)