Solved

Exchange 2007 move-mailbox script for bulk move using powershell

Posted on 2008-10-05
3
7,313 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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 …
To show how to create a transport rule 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 Mail Flow >> Rules tab.:  To cr…

770 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