Move 100gb of mailboxes

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

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <blockquote> <center> <hr> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <drupal6>, <html>, <java>, <javascript>, <php>, <posh>.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.