Solved

Exchange 2007 move-mailbox script for bulk move using powershell

Posted on 2008-10-05
3
7,328 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 71

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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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