?
Solved

Exchange 2007 move-mailbox script for bulk move using powershell

Posted on 2008-10-05
3
Medium Priority
?
7,352 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 750 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 750 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

After hours on line I found a solution which pointed to the inherited Active Directory permissions . You have to give/allow permissions to the "Exchange trusted subsystem" for the user in the Active Directory...
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
This video discusses moving either the default database or any database to a new volume.
Suggested Courses

777 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