Home > Exchange, Powershell > Exchange 2010 Mailbox Moves from CSV file

Exchange 2010 Mailbox Moves from CSV file

Recently during our Exchange migration I wanted a way to automate our mailbox moves.  Even though PowerShell makes this is very easy to script I couldn’t just use a normal filter because the mailboxes I am moving need go to one of three different databases.   I couldn’t use the New-MoveRequest cmdlet with a normal filter because none of the mailboxes had any common attributes to filter on.    Instead I created a CSV file with the mailbox name and the target databases.  In the past this would have meant many lines of VBscript code but with PowerShell this can all be done with a one liner!  Then using PowerShell I read this information in and pipe it over to the New-MoveRequest cmdlet to initiate the mailbox moves. 

My CSV file looks like this.

UserID TargetDB
User01 MBX01
User02 MBX03
User03 MBX02

The PowerShell script looks like this.

Import-Csv .\Filename.csv | % {New-MoveRequest -Identity $_.UserID 

-TargetDatabase $_.TargetDB}

I also created another one for ad-hoc moves.  This Powershell script allows me to specify the CSV file that I want to use instead of hardcoding it into the script.


$csvfile = Read-Host "Enter in the name of the CSV File that contains the mailboxes you want to move"

Import-Csv $csvfile | % {New-MoveRequest -Identity $_.UserID -TargetDatabase $_.TargetDB}

If you haven’t started using PowerShell for scripting tasks I highly recommend that you start looking into it.  It’s got a bit of a learning curve but it’s very powerful once your get a good grasp on it.

Categories: Exchange, Powershell Tags: ,
  1. Andor
    October 8, 2012 at 12:56 pm

    Hi Mike,

    Thanks for sharing this.

    I am exploring the possibility to automate the $_.TargetDB and I am looking for a way to automate the migration of mail-objects over the available mailbox-databases.

    Any thoughts?


    • October 9, 2012 at 9:26 am

      Hi Andor,

      Do you mean you are looking to randomize TargetDB and spread it over a number of databases while doing bulk migrations?


      • Andor
        October 9, 2012 at 11:02 am

        Hi Mike,

        Not randomize, but target a specific (number of DB’s) during a bulk migration.

        If I would ‘randomize’ the bulk migration I could /would /will use the Exchange Replication Mechanism and suspend a specific (set of) database(s) from being provisioned; makes sense?


      • October 16, 2012 at 9:15 am

        Hi Andor,

        I don’t see how you would be able to target just specific DBs without assigning each one in the CSV file. You might be able to create an array of DB names in Powershell and loop through that instead of using the CSV file but that is beyond my PowerShell scripting abilities.


      • October 16, 2012 at 9:27 am

        Hi Mike,

        Thanks for your feedback.

        Same here, I have no technical idea how to do this. So I am utilizing the Exchange Replication Mechanism and suspend a specific (set of) database(s).


  2. August 27, 2013 at 9:55 am

    where can I add a -AutoSuspend? BTW this is a life savor! 🙂

    • August 27, 2013 at 10:32 am

      There is no -AutoSuspend parameter for the New-MoveRequest cmdlet. You can however use -SuspendWhenReadyToComplete after the -TargetDatabase parameter. This will suspend the move operation and before the status reaches CompletionInProgress. You would then have to use the Resume-MoveRequest cmdlet to force it to finish.

  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

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

Google photo

You are commenting using your Google 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

%d bloggers like this: