Scheduling Exchange mailbox moves in bulk with the Get-Mailbox -Database powershell command

Over the years, I had opted to skip database maintenance with moving mailboxes to new databases. Back in the old days, I used to copy mailbox after individual mailbox; however, with powershell and Exchange 2007 and above, you can schedule whole database worth of mailboxes at a time and multiples thereafter.

1. An Exchange server or system running Exchange Management Tools 

2.  Create an account with Organizational Admin permissions and Domain Admin permissions (i.e. powershell@garzafx.lcl)

3. Open powershell and run Set-ExecutionPolicy RemoteSigned to allow running your own scripts.

4. Create a folder labeled c:\scripts to store your scripts.

5.  Copy and paste the below into script file into a file labeled mailboxmoves.ps1. Modify database and server group as necessary.

#Adding Exchange Snap In to execute Exchange CmdLets in this scriptAdd-PSSnapin

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


Get-Mailbox -Database “garzafx\A2013” | Move-Mailbox -BadItemLimit ’10’-TargetDatabase “garzafx\ A2014″  -Confirm:$False

Get-Mailbox -Database ” garzafx\B2013″ | Move-Mailbox -BadItemLimit ’10’-TargetDatabase ” garzafx\B2014″  -Confirm:$False


6. Ensure you have adequate log space on your system and free space on your target drives.

7. Create a scheduled task labeled: mailboxmoves.

8. Run under service account (i.e. powershell@garzafx.lcl).

9. Select option to,”Run whether user is logged on or not.”

10. Choose, “Run with highest privileges enabled.”

11. Select trigger options (i.e. every day, 9PM) and verify status, enabled.

12. Under Actions tab, select,”Start a Program.”

13. For Program/script enter: C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe

14. Under Add-arguments,”-file -Command “& ‘C:\scripts\mailboxmoves.ps1′”

15. Click OK and enter credentials when prompted.

16.  After the scheduled task runtime, verify no mailboxes reside in your old databases (i.e. get-mailboxstatistics -database myexchangeserver\agarzafx2013). Then proceed with file and folder deletion.

NOTE: You can schedule as many database mailbox moves, just be mindful of time of day and storage, otherwise you might inadvertently take information stores offline.

Read More:

How To: Schedule PowerShell Script for an Exchange Task  (Exchange Server Share)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s