We're working on load balancing our mailbox storage groups and needed to thin down a database by about 100gb of data. This simple script will move up to 100gb from one storage group to a specific other storage group.
#Pull all mailboxes from Source DB
$fromdb = get
-mailboxdatabase
-server Exch1
| ?{$_.storagegroup
-match "lit hold"}
$sourcegrp = Get
-mailbox
-resultsize unlimited
-database
$fromDb
#Maximum amount of mailboxes to move.
$maxmbx = 100gb
#Some book keeping variables.
$currentsize = 0
$movegroup = @()
$index = 0
$undersize = $True
#Start picking mailboxes to move.
do {
$me = $sourcegrp[$index]
#Get Mailbox Size.
$ms = get
-mailboxstatistics
$me.distinguishedname
if ($ms -ne $null) {
$mbxSize = $ms.totalitemsize.value.tobytes
()
} else {$ms = 0}
#Add mailbox to group as long as under Limit.
if (($mbxSize +$currentsize) -lt $maxMbx) {
$moveGroup += $me
$currentsize += $ms.totalitemsize.value.tobytes
()
} else {
$UnderSize = $false
}
$index++
#Some on-screen reporting.
write-host $me,($currentsize /1gb
), $ms.totalitemsize
} while ($undersize -and $currentsize -lt $maxMbx -and $index -lt $sourcegrp.count
)
#Find location to move to.
$bestdb = get
-mailboxdatabase
-server Exch1
| ?{$_.storagegroup
-match "lithold2"}
#Move mailboxes, 24 at a time.
$status = $MoveGroup | Move
-Mailbox
-TargetDatabase
$bestdb.identity
-BadItemLimit
600 -MaxThreads
24 -preservemailboxsizelimit
-confirm:
$FALSE
#generate reporting... Need to copy code from other script.. :)
Comments
Post new comment