Powershell: Keeping track of data being transferred during Exchange migrations


During a migration from legacy Exchange to Exchange 2013, perhaps one of the most important details to keep track of is the amount of data involved in the migrations.  Knowing the total data size remaining to migrate, total data size that has been migrated, and total data size of what is currently being migrated are extremely useful to provide status and outline progress to the client.
 
Below is a series of PowerShell commands that can used to obtain those details.


Total Data that has been migrated:

Total size of all Exchange 2013 mailboxes combined:
[math]::round((get-mailbox -resultsize unlimited | ?{$_.exchangeversion -like "0.20 (15.0.0.0)"} | Get-MailboxStatistics | ForEach-Object {([Microsoft.Exchange.Data.ByteQuantifiedSize]::Parse($_.TotalItemSize)).Tomb()} | Measure-Object -sum).sum / 1024,2)

Total Data still needing to be migrated:

Total size of all Exchange 2010 mailboxes combined:
[math]::round((get-mailbox -resultsize unlimited | ?{$_.exchangeversion -like "0.10 (14.0.100.0)"} | Get-MailboxStatistics | ForEach-Object {([Microsoft.Exchange.Data.ByteQuantifiedSize]::Parse($_.TotalItemSize)).Tomb()} | Measure-Object -sum).sum / 1024,2)

 Total size of all Exchange 2007 mailboxes combined:
[math]::round((get-mailbox -resultsize unlimited | ?{$_.exchangeversion -like "0.1 (8.0.535.0)"} | Get-MailboxStatistics | ForEach-Object {([Microsoft.Exchange.Data.ByteQuantifiedSize]::Parse($_.TotalItemSize)).Tomb()} | Measure-Object -sum).sum / 1024,2)

Total Data currently being migrated:

Get total size of all mailboxes currently being migrated via migration batches:
$Currentbatch = get-migrationuser -resultsize unlimited | ?{$_.status -ne "Completed"}
$currentbatchtotal = foreach ($mb in $currentbatch) {get-mailboxstatistics $mb.identifier}
[math]::round(($currentbatchtotal | ForEach-Object {([Microsoft.Exchange.Data.ByteQuantifiedSize]::Parse($_.TotalItemSize)).ToMb()} | Measure-Object -sum).sum /1024,2)



These commands will output total size in GB.  Although the function 'toGb()' could be substituted in lieu of 'toMB()' directly on the get-mailboxstatistics command, this would give results of '0' for mailboxes smaller than 1GB and not include anything over each 1GB break.  Therefore to achieve correct results we first use 'toMB()' and sum that and divide by 1024.