How to Move Exchange Mailboxes in a Text File using PowerShell

When you’re planning to migrate Exchange mailboxes you might choose to create lists of users to move and store them in text files.  With the Exchange Management Shell you can then use the text files as inputs to PowerShell commands to execute the moves.

This method starts with the Get-Content PowerShell command.  Get-Content can be used to read in a list of mailboxes from a text file, for example:

[PS] C:\>Get-Content C:\Admin\users.txt
Aisha.Bhari
Andrew.O'Grady
Denise.Dartnell
Garth.Gibbons
Harinder.Rahman
Jagir.Ward
Jas.Dowden
Joanna.Hughes
Joy.Singh
Laoise.Curtis
Lydia.Haines
Maggie.Hengist
Michael.Phillips
Nancy.Scott
Pakwei.Dean
Prathee.Dar
Ravi.Edmonds
Rowena.Khan
Sharmila.Hafri
Stuart.Beauchamp
Tina.Miller
Wendy.Fyson
TestMB BR

This output can then be piped to the commands that are used to move the mailboxes. For Exchange Server 2007 this would be:

[PS] C:\>Get-Content C:\Admin\users.txt | Move-Mailbox -TargetDatabase  -Confirm:$false

Note the -Confirm:$false that prevents you from having to manually confirm each move.

For Exchange Server 2010 mailbox moves the commands are different:

[PS] C:\>Get-Content C:\Admin\users.txt | New-MoveRequest -TargetDatabase MB-HO-01

Note that if you wanted to test your command syntax without actually moving the mailboxes just use the -WhatIf paramater, for example:

[PS] C:\>Get-Content C:\Admin\users.txt | New-MoveRequest -TargetDatabase MB-HO-01 -WhatIf
What if: Creating move request "exchangeserverpro.net/Company/Users/Branch Office/Aisha.Bhari".
What if: Creating move request "exchangeserverpro.net/Company/Users/Branch Office/Andrew.O'Grady".
What if: Creating move request "exchangeserverpro.net/Company/Users/Branch Office/Denise.Dartnell".
What if: Creating move request "exchangeserverpro.net/Company/Users/Branch Office/Garth.Gibbons".
What if: Creating move request "exchangeserverpro.net/Company/Users/Branch Office/Harinder.Rahman".
What if: Creating move request "exchangeserverpro.net/Company/Users/Branch Office/Jagir.Ward".
What if: Creating move request "exchangeserverpro.net/Company/Users/Branch Office/Jas.Dowden".
What if: Creating move request "exchangeserverpro.net/Company/Users/Branch Office/Joanna.Hughes".
What if: Creating move request "exchangeserverpro.net/Company/Users/Branch Office/Joy.Singh".
What if: Creating move request "exchangeserverpro.net/Company/Users/Branch Office/Laoise.Curtis".
What if: Creating move request "exchangeserverpro.net/Company/Users/Branch Office/Lydia.Haines".
What if: Creating move request "exchangeserverpro.net/Company/Users/Branch Office/Maggie.Hengist".
What if: Creating move request "exchangeserverpro.net/Company/Users/Branch Office/Michael.Phillips".
What if: Creating move request "exchangeserverpro.net/Company/Users/Branch Office/Nancy.Scott".
What if: Creating move request "exchangeserverpro.net/Company/Users/Branch Office/Pakwei.Dean".
What if: Creating move request "exchangeserverpro.net/Company/Users/Branch Office/Prathee.Dar".
What if: Creating move request "exchangeserverpro.net/Company/Users/Branch Office/Ravi.Edmonds".
What if: Creating move request "exchangeserverpro.net/Company/Users/Branch Office/Rowena.Khan".
What if: Creating move request "exchangeserverpro.net/Company/Users/Branch Office/Sharmila.Hafri".
What if: Creating move request "exchangeserverpro.net/Company/Users/Branch Office/Stuart.Beauchamp".
What if: Creating move request "exchangeserverpro.net/Company/Users/Branch Office/Tina.Miller".
What if: Creating move request "exchangeserverpro.net/Company/Users/Branch Office/Wendy.Fyson".
What if: Creating move request "exchangeserverpro.net/Users/TestMB BR".

When the moves are complete you can use a similar technique to verify that each user in the list was moved successfully to the target database.

[PS] C:\>Get-Content C:\Admin\users.txt | Get-Mailbox | ft name,database

Name                                                        Database
----                                                        --------
Aisha.Bhari                                                 MB-BR-01
Andrew.O'Grady                                              MB-BR-01
Denise.Dartnell                                             MB-BR-01
Garth.Gibbons                                               MB-BR-01
Harinder.Rahman                                             MB-BR-01
Jagir.Ward                                                  MB-BR-01
Jas.Dowden                                                  MB-BR-01
Joanna.Hughes                                               MB-BR-01
Joy.Singh                                                   MB-BR-01
Laoise.Curtis                                               MB-BR-01
Lydia.Haines                                                MB-BR-01
Maggie.Hengist                                              MB-BR-01
Michael.Phillips                                            MB-BR-01
Nancy.Scott                                                 MB-BR-01
Pakwei.Dean                                                 MB-BR-01
Prathee.Dar                                                 MB-BR-01
Ravi.Edmonds                                                MB-BR-01
Rowena.Khan                                                 MB-BR-01
Sharmila.Hafri                                              MB-BR-01
Stuart.Beauchamp                                            MB-BR-01
Tina.Miller                                                 MB-BR-01
Wendy.Fyson                                                 MB-BR-01
TestMB BR                                                   MB-BR-01
About Paul Cunningham

Paul is a Microsoft Exchange Server MVP and publisher of Exchange Server Pro. He also holds several Microsoft certifications including for Exchange Server 2007, 2010 and 2013. Connect with Paul on Twitter and Google+.

Comments

  1. Thanks Paul , This help me move over 500 mailbox with out any issue .

Leave a Comment

*

We are an Authorized DigiCert™ SSL Partner.
Loading...

Still running Exchange 2003? Time to get moving and start your upgrade. Find out how - Click Here