To move a single exchange 2007 mailbox within powershell from one database to another you would use the following command.
Move-mailbox –identity “%username%” –targetdatabase “%DB%”
This would be the equivalent of right clicking on a user object with the exchange console and choosing move mailbox. However the real power of powershell comes into play when you want to move multiple mailboxes from one database to another. In order to do that you would combine the move-mailbox cmdlet with get-mailbox. A simple usage would be something like.
Get-mailbox | move-mailbox –targetdatabase “%DB%”
This would move all mailboxes on the exchange server to the target database, however you may find that you already have a few mailboxes on the target database or you want to move users from a specific database to another database (if you had 3 databases for example). For this you could use:
Get-mailbox –database “%sourceDB%” | move-mailbox –targetdatabase “%DB%”
This would ensure that all mailbox from the source database are moved to the target. This process is not quick however as it opens each mailbox and creates another at the target then moves messages and folders across to the target. If you specify more than one user (or like above feed the move-mailbox mailboxes as multiple variables) then exchange will move 4 mailboxes at a time. During the move the mailboxes being copied will not be available whilst they are transferred.
You can also check what mailboxes reside on the database by typing get-mailbox –database “%DB%” you can use this before you move the mailboxes to get a good idea of how many you are moving, and you can also use it after the move-mailbox action has completed to ensure that non have been missed.
If the move-mailbox action errors on any particular mailbox (usually it will be because of corrupted mail items in the mailbox) then the mailbox move will not complete for that mailbox. This will leave a complete mailbox for the user on the source database and a partial mailbox on the destination. However after a few minutes exchange will delete the partial copy and you can try the move again. If the move fails because of corrupted items in the mailbox then you can force the move to occur by using the –baditemlimit variable if you simply must copy the mailbox, setting the limit at 1000 should cater for all really.
Move-mailbox –identity “username” –targetdabase “%DB%” –baditemlimit 1000
Subscribe to vhorizon
DisclaimerThis blog and any other post made by me on the internet is representative of my views only, they are not the views of my past/current/future employers.