Exchange Migration: Split mailboxes alphabetically across databases

When migrating from Exchange 2010 to Exchange 2013, it makes sense to distribute the mailboxes alphabetically to the new Exchange 2013 databases. I have therefore created a script that divides all mailboxes of a source database into the target databases according to the first letter of the name:

param
(
[string]$Database
,
[string]$Defaultdatabase
,
[bool]$CreateMoveRequest
)

write-host "

Process mailboxes in database $database
—————————————————
" -foregroundcolor green

if ($CreateMoveRequest)
{
write-host " Mailboxes are moved and displayed!" -foregroundcolor yellow
write-host ""

}
else
{
write-host " Mailboxes are not moved, only displayed." -foregroundcolor green
write-host ""
}

$mailboxlist = Get-Mailbox -database $database -ResultSize unlimited
foreach ($mailbox in $mailboxlist)
{
$displayname = $mailbox.displayname
switch -Regex ($displayname.substring(0,1))
{
"[A-C]" {$mailboxdatabase = "A-C database"}
"[D-F]" {$mailboxdatabase = "D-F database"}
"[G-J]" {$mailboxdatabase = "G-J database"}
"[K-L]" {$mailboxdatabase = "K-L database"}
"[M-O]" {$mailboxdatabase = "M-O database"}
"[S]" {$mailboxdatabase = "S database"}
"[T-Z]" {$mailboxdatabase = "T-Z database"}
default {$mailboxdatabase = "$defaultdatabase"}
}

$currentmbxdatabase = $mailbox.database.name
if ($currentmbxdatabase -ne $mailboxdatabase)
{
if ($CreateMoveRequest)
{
$move = New-MoveRequest -Identity $mailbox -TargetDatabase $mailboxdatabase
}
Write-Host "$displayname is moved to database $mailboxdatabase"
}

}
write-host ""

 

The syntax is as follows (save script above in move-mailboxes.ps1):

move-mailboxes -database -defaultdatabase -createmoverequest $true

-Database specifies the source database

-DefaultDatabase specifies a default database if no match is found, for example if the name starts with a number

-$true directly generates the corresponding move requests, $false only indicates to which database the mailbox will be moved, but does not yet create a move request.

2 thoughts on “Exchange Migration: Postfächer alphabetisch auf Datenbanken aufteilen”

Leave a Comment