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 https://www.catapultsystems.com/tharrington/
#
# 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.