Friday, June 11, 2010

Mailbox Migration to Exchange 2010 (PowerShell)

As stated in my previous post, I am no scripting guru or will I ever claim to be.  My primary purpose for creating this script is to force myself to learn about PowerShell scripting. 

I am sure that there is a more efficient or better approach here, so please leave comments and let me know.

The following script is written to migrate mailboxes (from Exchange 2003, 2007, or 2010) to an Exchange 2010 database.  This script could easily be modified if your target database was on Exchange 2007, but for now it is just written for Exchange 2010.

##########################################################################
# This script is for migrating mailboxes to Exchange 2010
# There is no warranty, use at your own risk
# Author: Tim Harrington
http://HowDoUC.blogspot.com
#
# Some of the methods in this script rely on Quest AD PowerShell Commands
# Free download at
http://www.quest.com/powershell/activeroles-server.aspx
##########################################################################

# Initial Menu to select method of selecting mailboxes to move
#
Write-Host " "
Write-Host "1 = Move mailboxes by user name"
Write-Host "2 = Move mailboxes by security group"
Write-Host "3 = Move mailboxes by database"
Write-Host "4 = Move mailboxes by OU"
Write-Host " "
Write-Host "Full Report = Run Report -> c:\temp\FullMoveReport.txt"
Write-Host "Error Report = Run Report -> c:\temp\ErrorMoveReport.txt"
Write-Host " "
$Method = Read-Host "Please select an option from the list above?"
#
# Method 1 = Move mailboxes by user name
If ($Method -eq 1)
{
Write-Host "You have choosen to migrate mailboxes by specifying the user name"
Get-MailboxDatabase
$TargetDatabaseName = Read-Host "Type the database that you want to migrate user(s) to"
$UserName = Read-Host "Type the user name that will be migrated"
Write-Host ("Moving user: " +$UserName +" to database: " +$TargetDatabaseName)
New-MoveRequest -identity $UserName -TargetDatabase $TargetDatabaseName
}

# Method 2 = Move mailboxes by security group
If ($Method -eq 2)
{
Write-Host " "
Write-Host "You have choosen to migrate mailboxes by specifying an AD security group"
Write-Host " "
Write-Host "This script relies on Quest AD PowerShell Commands"
Write-Host "Download at http://www.quest.com/powershell/activeroles-server.aspx"
Write-Host " "
Add-PSSnapin Quest.ActiveRoles.ADManagement
$ADSecGroupName = Read-Host "Enter AD security group that you want to migrate"
Get-QADUser -MemberOf $ADSecGroupName | ft
Write-Host "The above list of users will get migrated!!"
Write-Host " "
Get-MailboxDatabase | ft
$TargetDatabaseName = Read-Host "Type the database that you want to migrate user(s) to"

#Loop through each mailbox
foreach ($mailbox in (Get-QADUser -MemberOf $ADSecGroupName))
{$displayname = $mailbox.Displayname
New-MoveRequest -Identity $displayname -TargetDatabase $TargetDatabaseName}
}
#
# Method 3 = Move mailboxes by database
If ($Method -eq 3)
{
Write-Host "You have choosen to migrate mailboxes from one database to another database"
Get-ExchangeServer | ft
$SourceServer = Read-Host "What is the source server from list above?"
Get-MailboxDatabase -Server $SourceServer | ft
$SourceDatabaseName = Read-Host "What is the SOURCE database from list above? (Type exactly from list)"
Get-MailboxDatabase | ft
$TargetDatabaseName = Read-Host "What is the TARGET database from list above? (Type exactly from list)"
Write-Host ("Moving users from source database: " +$SourceDatabaseName +" to target database: " +$TargetDatabaseName)
Get-Mailbox -Database $SourceDatabaseName
New-MoveRequest -TargetDatabase $TargetDatabaseName
}
#
# Method 4 = Move mailboxes by OU
If ($Method -eq 4)
{
Write-Host " "
Write-Host "You have choosen to migrate mailboxes by specifying an AD OU"
Write-Host " "
Write-Host "This script relies on Quest AD PowerShell Commands"
Write-Host "Download at http://www.quest.com/powershell/activeroles-server.aspx"
Write-Host " "
Add-PSSnapin Quest.ActiveRoles.ADManagement
Get-QADObject -Type OrganizationalUnit | ft
$ADOUName = Read-Host "Enter AD OU that you want to migrate"
Get-QADUser -Searchroot $ADOUName -SearchScope OneLevel | ft
Write-Host "The above list of users will get migrated!! (This does not include sub-OUs)"
Write-Host " "
Get-MailboxDatabase | ft
$TargetDatabaseName = Read-Host "Type the database that you want to migrate user(s) to"

#Loop through each mailbox
foreach ($mailbox in (Get-QADUser -Searchroot $ADOUName))
{$displayname = $mailbox.Displayname
New-MoveRequest -Identity $displayname -TargetDatabase $TargetDatabaseName}
}
#
# Save off full report
If ($Method -eq "Full Report")
{
Get-MoveRequest | Get-MoveRequestStatistics | Select DisplayName, Status, TotalItemSize, TotalMailboxItemCount, PercentComplete, BytesTransferred, ItemsTransferred | Out-File -FilePath "c:\temp\FullMoveUserLog.txt" -append -noClobber
}

# Save off error report
If ($Method -eq "Error Report")
{
Get-MoveRequest | Get-MoveRequestStatistics where {$_.Status -like "*error*"} | Select DisplayName, Status, TotalItemSize, TotalMailboxItemCount, PercentComplete, BytesTransferred, ItemsTransferred | Out-File -FilePath "c:\temp\ErrorMoveUserLog.txt" -append -noClobber
}
#############################################################################

Hope this helps some folks out there.  Comments are welcome.

18 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Thanks for sharing this information. But the article is targeting migration into Exchange 2010 mailboxes. But I tried the above mentioned way too for migration into Exchange 2013 from 2007, but couldn't get success.
    Therefore I went for a utility of Exchange Migration. But in the process of finding a utility, I came to know that it isn't possible to migrate mailboxes directly from one exchange server to another. Therefore I followed the way to Export Exchange mailboxes into PST and then import all PST files into another exchange server, and then configured all services like OWA, ECP etc in a proper manner.
    It was really an effortless way of migration with export & import mailbox technique by using Exchange recovery tool.

    ReplyDelete
  3. Really good article, It provides the step by step guide to exchange server 2007 sp3and I saw more information about this topic from https://softcart.wordpress.com/exchange-server-migration/ that helps to migrate any exchange server to exchange server.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Given article is very helpful and very useful for my admin, and pardon me permission to share articles here hopefully helped :

    Obat infeksi usus
    Obat Radang Tenggorokan Kronis
    Obat Sekelan
    Obat epilepsi
    Obat benjolan di kelopak mata

    ReplyDelete
  6. As stated in my previous post, I am no scripting guru or will I ever claim to be. My primary purpose for creating this script is to force myself to learn about PowerShell scripting. wholesale apparel , bulk white t shirts canada , wholesale t shirts with free shipping , low cost t shirts wholesale , cheap bulk blank shirts , bulk grey t shirts , bulk childrens clothing , discount designer baby clothes , cheap dresses for kids , buy baby clothes

    ReplyDelete
  7. Mozocare in india's biggest medical tycoon are providing medical information about best ent surgeon. They write a blog blog on the top notch ENT Surgeons and Doctors. for more details you may visit :

    Treattments In Turkey

    ReplyDelete
  8. children's favorites happy birthday song mp3 download, best happy birthday song download, happy birthday song in hindi mp3 download, best happy birthday song download, happy birthday to you original song download, birthday song download, i wish you happy birthday song mp3 download, birthday shayari

    Children Favorites Happy Birthday Song Mp3 Download

    ReplyDelete
  9. Good evening. Good evening. I have wanted to write this service analysis. It really shocked me, actually, because I did not see the best of its kind compared to related places of dating this, where I could find my second half. This place will still encourage you to find your love, because it helped me one time. romanian brides The website is built in a very beautiful way so the functionality of this site is really rich and just, the website just surprised me with pleasure. I recommend this place to a lot of single guys!

    ReplyDelete

  10. We are helping amazon seller's to reinstate their suspended seller account. Aplus global ecommerce is guide companies to write perfect amazon appeal letter and full proof amazon suspension appeal.

    amazon suspension appeal

    ReplyDelete
  11. Oh, thanks so much! Glad you found it on dotcomsecrets, clicked, read, and commented! �� About Shoulder Replacement Surgery in India

    ReplyDelete
  12. Definitely a technical and coding help you left for us. Though it's 2021 and things are on its rapid changes, I found it still useful. I am also not a guy with rich scripting knowledge but I would like to agree, you did really an awesome job particularly those who would like to customize and migrating their mailbox. This is incredibly adorable. Much appreciation for sharing this handy project. I also would like to share an article Getnewmailbox especially those those guys who are looking for about how digital mailboxes work and compare the benefits to choose the best virtual mailbox service. Hope some readers here will find this useful.

    ReplyDelete
  13. Yeah, mailbox migration to porwershell script. This is really an amazing technical support. Anyway, as a business owner, surely you like to find your business into a growing trend. To get this growth you of course need some IT support of course with professional hands. IT company Pickering can be that hand to grab the best success, It provides optimal Infrastructure Technology solutions that are customized to your company needs.

    ReplyDelete