Each migration I work on has a different set of requirements to move users from Exchange 2003 to Exchange 2007. Some customers use the Exchange Manager Console to move users, which works fine. My latest customer asked me to help them move mailboxes based on users in a specific OU. So I created a powershell command that will export the alias and database for accounts that reside in a specific OU. Once we had the output file we could pipe the CSV file (with a couple modifications) into our move mailbox script and boom they should be good to go.

Just an FYI you can use the mailbox move script in this blog without running the Export Users powershell command.

You can find the script and sample output here:

get-mailbox -organizationalunit domain.com/Resources/Users"| Select database, @{Name='alias';Expression={[string]::join(";", ($_.alias))}} | Export-CSV mailboxmove.csv

Output file

#TYPE System.Management.Automation.PSCustomObject

Database

alias

EX03MB1First Storage GroupMailbox Store (EX03MB1)

eford

CLTEX07MB02First Storage GroupMailbox Database

afox

EX07MB1Second Storage GroupFirst Database

narmstrong

EX03MB1Second Storage GroupFirst Database

omoreland

EX03MB1Second Storage GroupFirst Database

axpojr

EX03MB1First Storage GroupMailbox Store (EX03MB1)

jexpo

EX03MB1Second Storage GroupFirst Database

expo-East

EX07MB1Second Storage GroupFirst Database

awhite

EX07MB1Second Storage GroupFirst Database

bwhite

EX03MB1Second Storage GroupFirst Database

ajohnson

EX03MB1Second Storage GroupFirst Database

bjohnson

EX03MB1Second Storage GroupFirst Database

cjohnson

EX03MB1First Storage GroupMailbox Store (EX03MB1)

aford

EX03MB1First Storage GroupMailbox Store (EX03MB1)

dford

Script

$Logfile = "c:mailboxmovelogfile.txt"

$GC = "DC Name"

$error.Clear()

$mailboxuserfile = import-csv c:users.csv

foreach ($mailboxuser in $mailboxuserfile)

{

$alias = $mailboxuser.alias

$Targetdatabase = $mailboxuser.Targetdatabase

$message = "moving user -> " + $alias

$date = get-date

write-output $date $message | out-file -filepath $Logfile -append -noclobber

move-mailbox -id $alias -targetdatabase $Targetdatabase -globalcatalog $gc -confirm:$false

if($error.count -ne 0)

{

$message = "moving user -> " + $alias + "move failed"

write-output $date $message | out-file -filepath $Logfile -append -noclobber

$message = "Error: " + $error[0].ToString()

write-output $date $message | out-file -filepath $Logfile -append -noclobber

$error.Clear()

}

}

CSV file

alias,Targetdatabase
awhite,EX07MB1first storage groupmailbox database
bwhite,EX07MB1first storage groupmailbox database

Log File output....now we can add more information like statusmessage

Monday, November 09, 2009 11:00:34 PM
moving user ->  awhite

Monday, November 09, 2009 11:01:03 PM
moving user ->  bwhite

XML file by default C:Program FilesMicrosoftExchange ServerLoggingMigrationLogs

[11/9/2009 11:01:03 PM] [0] Executing Command: 'move-mailbox -id $alias -targetdatabase $Targetdatabase -globalcatalog $gc -confirm:$false'
[11/9/2009 11:01:03 PM] [0] Searching objects "EX07MB1Second Storage GroupFirst Database" of type "MailboxDatabase" under the root "$null".
[11/9/2009 11:01:03 PM] [0] Previous operation run on domain controller 'DC2.domain.com'.
[11/9/2009 11:01:03 PM] [0] Searching objects "bwhite" of type "ADUser" under the root "$null".
[11/9/2009 11:01:03 PM] [0] Previous operation run on global catalog server 'DC2.domain.com'.
[11/9/2009 11:01:03 PM] [0] Processing object "domain.com/Resources/Users/Berry White".
[11/9/2009 11:01:03 PM] [0] Searching objects "EX03MB1" of type "Server" under the root "$null".
[11/9/2009 11:01:03 PM] [0] Previous operation run on domain controller 'DC2.domain.com'.
[11/9/2009 11:01:03 PM] [0] Searching objects "EX03MB1First Storage GroupMailbox Store (EX03MB1)" of type "MailboxDatabase" under the root "$null".
[11/9/2009 11:01:03 PM] [0] Previous operation run on domain controller 'DC2.domain.com'.
[11/9/2009 11:01:03 PM] [0] Ending processing.
[11/9/2009 11:01:03 PM] [0] [bwhite] The operation has started.
[11/9/2009 11:01:03 PM] [0] [bwhite] Approving object.
[11/9/2009 11:01:03 PM] [0] [bwhite] Trying to open mailbox:
 szServerLegacyDN: /o=First Organization/ou=First Administrative Group/cn=Configuration/cn=Servers/cn=EX03MB1
 szUserLegacyDN: /o=First Organization/ou=First Administrative Group/cn=Recipients/cn=bwhite
 szServer: EX03MB1.domain.com
[11/9/2009 11:01:03 PM] [0] [bwhite] Open mailbox succeeded.
[11/9/2009 11:01:04 PM] [0] [bwhite] The operation has finished.
[11/9/2009 11:01:04 PM] [0] Searching objects "domain.com/Resources/Users/Berry White" of type "ADUser" under the root "$null".
[11/9/2009 11:01:04 PM] [0] Previous operation run on global catalog server 'DC2.domain.com'.
[11/9/2009 11:01:04 PM] [0] [bwhite] The operation has started.
[11/9/2009 11:01:04 PM] [0] [bwhite] Approving object.
[11/9/2009 11:01:04 PM] [0] [bwhite] Opening source mailbox.
[11/9/2009 11:01:04 PM] [0] [bwhite] Trying to open mailbox:
 szServerLegacyDN: /o=First Organization/ou=First Administrative Group/cn=Configuration/cn=Servers/cn=EX03MB1
 szUserLegacyDN: /o=First Organization/ou=First Administrative Group/cn=Recipients/cn=bwhite
 szServer: EX03MB1.domain.com
[11/9/2009 11:01:04 PM] [0] [bwhite] Open mailbox succeeded.
[11/9/2009 11:01:04 PM] [0] [bwhite] Trying to lock mailbox:
 szServer: EX03MB1.domain.com
 pguidMdb: {36DFBEEB-51B2-4F88-90AC-7D7BF63DA4F0}
 pguidMailbox: {ACECF3F4-8464-4914-90CA-B3D3A32739C5}
[11/9/2009 11:01:14 PM] [0] [bwhite] Mailbox was locked successfully.
[11/9/2009 11:01:14 PM] [0] [bwhite] Preparing mailbox to be moved.
[11/9/2009 11:01:14 PM] [0] [bwhite] Copying basic mailbox information from source mailbox:
 szServerSrc: EX03MB1.domain.com
 szServerDest: EX07MB1.domain.com
 pguidMdbSrc: {36DFBEEB-51B2-4F88-90AC-7D7BF63DA4F0}
 pguidMdbDest: {A6ED16F4-3796-4A7E-A4C9-0685F4FD6F95}
 pguidMailbox: {ACECF3F4-8464-4914-90CA-B3D3A32739C5}
[11/9/2009 11:01:14 PM] [0] [bwhite] Basic mailbox information was copied successfully.
[11/9/2009 11:01:14 PM] [0] [bwhite] Opening destination mailbox.
[11/9/2009 11:01:14 PM] [0] [bwhite] Trying to open mailbox:
 szServerLegacyDN: /o=First Organization/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Configuration/cn=Servers/cn=EX07MB1
 szUserLegacyDN: /o=First Organization/ou=First Administrative Group/cn=Recipients/cn=bwhite
 szServer: EX07MB1.domain.com
[11/9/2009 11:01:14 PM] [0] [bwhite] Open mailbox succeeded.
[11/9/2009 11:01:14 PM] [0] [bwhite] Trying to lock mailbox:
 szServer: EX07MB1.domain.com
 pguidMdb: {A6ED16F4-3796-4A7E-A4C9-0685F4FD6F95}
 pguidMailbox: {ACECF3F4-8464-4914-90CA-B3D3A32739C5}
[11/9/2009 11:01:24 PM] [0] [bwhite] Mailbox was locked successfully.
[11/9/2009 11:01:24 PM] [0] [bwhite] Moving messages.
[11/9/2009 11:01:25 PM] [0] [bwhite] 0 items could not be moved to the target mailbox.
[11/9/2009 11:01:25 PM] [0] [bwhite] Updating attributes.
[11/9/2009 11:01:25 PM] [0] [bwhite] Messages moved. Closing connections.
[11/9/2009 11:01:25 PM] [0] [bwhite] Trying to unlock mailbox:
 szServer: EX07MB1.domain.com
 pguidMdb: {A6ED16F4-3796-4A7E-A4C9-0685F4FD6F95}
 pguidMailbox: {ACECF3F4-8464-4914-90CA-B3D3A32739C5}
[11/9/2009 11:01:25 PM] [0] [bwhite] Mailbox was unlocked successfully.
[11/9/2009 11:01:25 PM] [0] [bwhite] Deleting mailbox from mailbox database:
 szServer: EX03MB1.domain.com
 pguidMdb: {36DFBEEB-51B2-4F88-90AC-7D7BF63DA4F0}
 pguidMailbox: {ACECF3F4-8464-4914-90CA-B3D3A32739C5}
[11/9/2009 11:01:25 PM] [0] [bwhite] Mailbox '{ACECF3F4-8464-4914-90CA-B3D3A32739C5}' was deleted successfully.
[11/9/2009 11:01:25 PM] [0] [bwhite] The operation has finished.
[11/9/2009 11:01:25 PM] [0] Searching objects "domain.com/Resources/Users/Berry White" of type "ADUser" under the root "$null".
[11/9/2009 11:01:25 PM] [0] Previous operation run on domain controller 'DC1.domain.com'.
[11/9/2009 11:01:25 PM] [0] Setting Exchange version "0.1 (8.0.535.0)" on object "domain.com/Resources/Users/Berry White".
[11/9/2009 11:01:25 PM] [0] Searching objects "EX07MB1.domain.com" of type "Server" under the root "$null".
[11/9/2009 11:01:25 PM] [0] Previous operation run on domain controller 'DC2.domain.com'.
[11/9/2009 11:01:25 PM] [0] [bwhite] Before applying RUS, the proxy addresses are:
 smtp:bwhite@domain.com
 X400:C=US;A= ;P=First Organizati;O=Exchange;S=White;G=Berry;
 SMTP:White.Berry@domain.com
[11/9/2009 11:01:25 PM] [0] Applying RUS policy to the given recipient "domain.com/Resources/Users/Berry White" with the home domain controller "DC1.domain.com".
[11/9/2009 11:01:25 PM] [0] The RUS server that will apply policies on the specified recipient is "EX07MB1.domain.com".
[11/9/2009 11:01:25 PM] [0] [bwhite] After applying Address List Service, the proxy addresses are:
 smtp:bwhite@domain.com
 X400:C=US;A= ;P=First Organizati;O=Exchange;S=White;G=Berry;
 SMTP:White.Berry@domain.com
[11/9/2009 11:01:25 PM] [0] Setting Exchange version "0.1 (8.0.535.0)" on object "domain.com/Resources/Users/Berry White".
[11/9/2009 11:01:25 PM] [0] Saving object "domain.com/Resources/Users/Berry White" of type "ADUser" and state "Changed".