Monday, 22 December 2008

Moving Specific Users via the Exchange Management Shell

About a year ago I published a two-part article over at msexchange.org on moving mailboxes in Exchange 2007. You can find part one here and part two here. In part two I covered how you can use the Exchange Management Shell to move mailboxes via the Move-Mailbox cmdlet. One of the examples I gave was how to move all the users from one mailbox database to another via the following cmdlet:

Get-Mailbox –Database “DCEXCH\First Storage Group\Mailbox Store (DCEXCH)” Move-Mailbox –TargetDatabase “E2K7\First Storage Group\Mailbox Database” –MaxThreads 10

Here you can see that all users on the database called Mailbox Store (DCEXCH) are moved to another database called Mailbox Database. The -MaxThreads parameter with a value of 10 means that 10 mailboxes are moved at a time.

This cmdlet is great if you really want to move all users on a database at the same time. I recently received an email asking how you can move a list of users at the same time, which admittedly is more likely in a migration scenario. For example, you may want to move just a manager and his secretary at the same time. Let's say you have three users that you wish to move, who could be located on completely different source databases. The key here is to use the array feature of the Exchange Management Shell and put the aliases of the mailboxes to move into the array. A sample script is:

$UsersToMigrate = "user1", "user2", "user3"
ForEach ($SingleUser in $UsersToMigrate) {Move-Mailbox -Identity $SingleUser -TargetDatabase "server\storage group\database" -Confirm:$false}

Here we create an array called $UsersToMigrate, which contains the aliases of the three users. We then loop through the array one user at a time, identifying a single user as $SingleUser. For each user, we run the Move-Mailbox cmdlet and move each mailbox to the desired database which is identified in the server\storage group\database name format. It's as easy as that.

No comments: