Solved

Exchange 2007 move-mailbox script for bulk move using powershell

Posted on 2008-10-05
3
7,290 Views
Last Modified: 2012-08-27
We are about to move users cross forest from Exchange 2003 to Exchange 2007. We have tested the command below which works perfect for moving a single mailbox. As I am not an expert with powershell, can somebody assist with creating a script that will do a bulk move of mailboxes based on a txt file with users aliases (or sam account).

This is what we have completed for 1 mailbox:
$SourceCredential = Get-Credential  (This is the username and password for source domain)
$TargetCredential = Get-Credential (This is the username and password for target domain)

Move-Mailbox -TargetDatabase "EX07\First Storage Group\Small Mailboxes" -Identity eric_sdaly -GlobalCatalog dc01.targetdomain.local -SourceForestGlobalCatalog dc01.sourcedomain.com SourceDomainController dc01.sourcedomain.com -NTAccountOU "OU=Secure,OU=Ireland,OU=User Accounts/Groups,DC=targetdomain,DC=local" -SourceForestCredential $SourceCredential -TargetForestCredential $TargetCredential -SourceMailboxCleanupOptions MailEnableSourceAccount

Hope someone can help on this.
Thanks
0
Comment
Question by:ericdaly
3 Comments
 
LVL 70

Accepted Solution

by:
Chris Dent earned 250 total points
ID: 22648453

Hey,

That should be quite easy actually :)

PowerShell has a nice CSV File Reader that can be used to read the input file, we could just loop through using that.

Imagine your text file (call it users.csv for this example) looked like this:

Username
bob
lucy
james
graham

The column header is important, with that we can do:

$UsersCSV = Import-CSV -Path "users.csv"

Which will let us loop through each like this:

$UsersCSV = Import-CSV -Path "users.csv"
foreach ($Line in $UsersCSV) {
    Move-Mailbox -TargetDatabase "EX07\First Storage Group\Small Mailboxes" `
        -Identity $Line.Username -GlobalCatalog dc01.targetdomain.local `
        -SourceForestGlobalCatalog dc01.sourcedomain.com -SourceDomainController dc01.sourcedomain.com `
        -NTAccountOU "OU=Secure,OU=Ireland,OU=User Accounts/Groups,DC=targetdomain,DC=local" `
        -SourceForestCredential $SourceCredential -TargetForestCredential $TargetCredential `
        -SourceMailboxCleanupOptions MailEnableSourceAccount
}

We can access each line with the ForEach loop, then we get the Username column with "$Line.Username". The ` used above just allows us to split the command over several lines, tends to make it easier on the eyes.

HTH

Chris
0
 
LVL 11

Assisted Solution

by:Sudhirchauhan3
Sudhirchauhan3 earned 250 total points
ID: 22648454
This is what you need. $users = get-content inputfile.txt  will read the aliases or samaccountname from the inputfile.txt . For each loop will iterate through the list and move the mailboxes.

Regards
Sudhir


$SourceCredential = Get-Credential  (This is the username and password for source domain)

$TargetCredential = Get-Credential (This is the username and password for target domain)

$users = get-content inputfile.txt

foreach ( $user in $users ) {

Move-Mailbox -TargetDatabase "EX07\First Storage Group\Small Mailboxes" -Identity $user -GlobalCatalog dc01.targetdomain.local -SourceForestGlobalCatalog dc01.sourcedomain.com SourceDomainController dc01.sourcedomain.com -NTAccountOU "OU=Secure,OU=Ireland,OU=User Accounts/Groups,DC=targetdomain,DC=local" -SourceForestCredential $SourceCredential -TargetForestCredential $TargetCredential -SourceMailboxCleanupOptions MailEnableSourceAccount
 

if ($? -ne True ) { 

write-host "Move-Mailbox Failed for user $user ."

}
 

}

Open in new window

0

Featured Post

Want to promote your upcoming event?

Attending an event? Speaking at a conference? Or exhibiting at a tradeshow? Easily inform your contacts by using a promotional banner in your email signature. This will ensure your organization’s most important contacts are in the know.

Join & Write a Comment

Easy CSR creation in Exchange 2007,2010 and 2013
Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now