Get Mailbox Sizes on Exchange with Powershell

Here is a quick and easy one!! Today we are preparing for another Office 365 migrations and we need to plan for the project Kick Off call with the client. We wanted to be able to provide and estimate on about how long we thought that it would take to sync the email between the on-premise Exchange and Office 365.

We needed to get the amount of data needing to migrate so I wrote this script.

I start off by using the Get-MailboxStatistics cmdlet and to use this you either need to run it in the Exchange Management Console or you need to add the Exchange snapin or Powershell will error stating that it doesn’t know about this cmdlet.

We will then take the results of this cmdlet and pipe them to the Where-Object cmdlet using the “|” and we will filter the results down to just mailboxes using the ObjectClass property.

Then we take those results and pipe them to the Sort-Object cmdlet to sort by the TotalItemSize property in descending order before piping those results to the Format-Table cmdlet to format the results in to a readable table.

The code that is within the @{} takes the DisplayName property and changes the column header to User and the TotalItemSize property and changes the column header to Total Size (MB). We also took the TotalItemSize property and used .Value.ToMB() to convert it to MB because if you ran this without it you will get values in MB, KB, and GB which will look horrible.

Last we took the entire results and used a little CMD prompt to output to the text file mailbox_size.txt in c:\temp. We could have just piped it again to the Out-File cmdlet but I figured why not.

Get-MailboxStatistics -Server 'localhost' | 
Where-Object {$_.ObjectClass -eq “Mailbox”} | 
Sort-Object TotalItemSize -Descending | 
Format-Table @{label=”User”;expression={$_.DisplayName}},@{label=”Total Size (MB)”;expression={$_.TotalItemSize.Value.ToMB()}}  -auto >> “c:\Temp\mailbox_size.txt”

Leave a Reply

Your email address will not be published.