Friday, August 2, 2013

New Bulk Mailbox Move Request

I've been working on several projects which are all tied together.
  1. PST Files to personal Archives
  2. Rehydrating of Stubs back into the mailbox.
  3. Moving Personal Archive Mailboxes into new DAGs.
So all these projects involve moving mailboxes around. Either to a new more spacious place along with keeping track of who has been done and who needs to be done. Or moving Personal Archives to dedicated server DAGs. Sometimes its necessary to combine older mailbox databases together to free up some space on the drive.

So, in short, I'm moving everyone's mailbox at least once. 25,000 Mailboxes. Also add 3000 Personal Archive mailboxes.

So I created a bulk mail mover that works for me. Get the script here.

UPDATE: Somehow when I posted this to poshcode.org, the section for sorting the results was omitted. I am sure I fat-fingered something somewhere. I added it back.

  • SourceDB - This designates the source mailbox database
  • TargetDB - This can be a single mailbox database or a group of mailbox databases. If given a group, the mailboxes are balanced across all of them by size.
  • Archive - denotes the mailbox to move is an Personal Archive. If this is absent only the primary is moved. This script never moves both.
  • NumberToMove - this is the number of mailbox you want to move - like 25
  • SizeLessThan - many times I just want all the mailbox under 2GB or something like that. You could combine this with -NumberToMove so that it only gets the first 25 of mailboxes below 1GB if you wanted.
  • Descending - this will get the largest mailboxes first. You could combine this with -NumberToMove and get the top 10 largest mailbox in a given mailbox database.
  • Notify - Send an email when finished. (Turns on Monitor.)
  • Monitor - monitor the progress for you in a continuous loop. Until there are no more Queued or Moving
  • Terminated -   This selects only mailboxes whose AD accounts have been disabled. I move these mailboxes to create Free Database Space -- mainly when combining mailbox databases to free up drive space.
  • LitHold - Same here, I want to move these to a particular place, or maybe just want to get an idea of how many there are and the size, etc.
I use this constantly now and think its a great tool for me.

It uses Quest (Now Dell) AD Tools mainly to select the archive mailboxes in a Mailbox Database. Selecting them via get-mailbox took forever!  QA Tools tool was 3 times faster!

Here's the function:
Function Find-ArchiveDBUSers {
param (
[string]$SourceDB,
[switch]$Statistics
)

# this took less than 1.5 seconds on 25000 mailboxes and 2000 archives
# Get-QADUser -IncludedProperties msexcharchivedatabaselink -SizeLimit 0 -LdapFilter "(msexcharchivedatabaselink=CN=<mailboxdatabaseName>,CN=Databases,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups,CN=<mydoamin>,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=<mydomain>,DC=com)"

# this took 46 second on 25000 mailboxes, and 2000 archives
# get-mailbox -Archive -ResultSize Unlimited | ?{$_.ArchiveDatabase -match "^$SourceDB$"}

$FilteredDB = "(msexcharchivedatabaselink=CN=" + $SourceDB + ",CN=Databases,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups,CN=<mydomain>,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=<mydomain>,DC=com)"
$user = Get-QADUser -IncludedProperties msexcharchivedatabaselink -SizeLimit 0 -LdapFilter "$FilteredDB"
if($Statistics) {
$user | %{get-mailboxstatistics $_.mail -archive}
} Else {
$user | %{get-mailbox $_.mail -archive}
}
}

I also wanted to do several things. Mainly get all the personal archive mailboxes under 2GB and move them to a group of mailbox databases. And balance the mailboxes over them all. There was a small problem of selecting the same database over and over. So as I decided where a mailbox would go, I added the size of that mailbox to the database then sorted again.

I added a -Monitor so I could have it email me when it's done. But it was clunky and I never use it. Maybe someone can refine that part ;)

So here's how I usually run this command

Our new personal Archive Databases are all name "ArchiveMBXDB001" thru "ArchiveMBXDB999" - I have not created that many, it's just a format -- we add them as we go.

This command gets all those Mailbox Databases no matter how many there are:
$MoveHere = get-mailboxdatabase | ? { $_.name -match "^archivembxdb\d{3}"}

Then I use my script this way:
New-BulkMailboxMoveRequest -TargetDB ($MoveHere) -Archive -NumberToMove 50 -SizeLessThan 2000 -Source OldArchive01

This will find all the Personal Archives in OldArchive01 database then pare that down to those that are under 2 GB in size. Of that set we trim it to 50 users, if there is that many.

Then we take our personal archive mailboxes and assign each one the smallest mailbox database.
Then we add the size of that PersonalArchive to the logged size of the mailbox database and then resort the mailbox databases so a new one is smallest. The next personal archive is assigned to that one, it's size added to the mailbox database size and resorted ... and so on ...

You get prompted at the end to accept the results, showing you sizes and destinations.

This has become a powerful tool in my arsenal.
As usual: "Your mileage may vary."