Get Exchange Online Mailbox Size in GB

   As mentioned in my previous post I was recently working with a customer to get started with Exchange Online PowerShell commandlets.  In this post I wanted to follow up and show one example of a difference in output from commandlets in Exchange 2010 on-premises vs. Exchange Online.



   The customer was interested in getting the size of mailboxes in GB.  For Exchange on-premises this is fairly easy.  A fellow PFE Gary Siepser wrote an article explaining how to accomplish this (click here).  Note that Gary’s script will not work when remoting from a local machine that doesn’t have the Exchange object model installed.  A similar type of scenario exists if you are executing PowerShell against Exchange Online.  The data type for TotalItemSize  being returned (ByteQuantifiedSize) exists in the Exchange namespace.  If the PowerShell session doesn’t have access to that namespace (or hasn’t loaded it) PowerShell works with an approximation of that data type.

   The customer found a sample script on this TechNet article that they attempted to use (minor edits by me to fit on page and remove references to deleted item size.)


Get-Mailbox -ResultSize Unlimited |
   Get-MailboxStatistics |
   Select DisplayName,StorageLimitStatus, `
   @{name="TotalItemSize (MB)"; expression={[math]::Round( `
   ($_.TotalItemSize.Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)}}, `
   ItemCount |
   Sort "TotalItemSize (MB)" -Descending |
   Export-CSV "C:My DocumentsAll Mailboxes.csv" -NoTypeInformation


  The script is targeted to Exchange 2010 but fails for Exchange Online.  In Exchange Online when referencing the TotalItemSize property though it does not have a Split method which ultimately causes the script to fail.



   A simple solution would be to add a call to the ToString method off of the TotalItemSize property (in bold on line 5 below).


Get-Mailbox -ResultSize Unlimited |
   Get-MailboxStatistics |
   Select DisplayName,StorageLimitStatus, `
   @{name="TotalItemSize (MB)"; expression={[math]::Round( `
   ($_.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)}}, `
   ItemCount |
   Sort "TotalItemSize (MB)" -Descending |
   Export-CSV "C:My DocumentsAll Mailboxes.csv" -NoTypeInformation


   This fixes the script to run but the numerous string replacements and splits are an eye sore to me.  I attempted to simplify the string manipulation with a regular expression (more info on regular expressions in PowerShell click here).  The result is a workable script that does one nice feature of adding a new member to the mailbox statistics called TotalItemSizeInBytes.  With this member you can then convert into any byte level (KB, MB, GB, etc.) that suits your needs.  You can download the full version of this script below (includes commands to connect to Exchange Online session).

$UserMailboxStats = Get-Mailbox -RecipientTypeDetails UserMailbox `
   -ResultSize Unlimited |
$UserMailboxStats |
   Add-Member -MemberType ScriptProperty -Name TotalItemSizeInBytes `
   -Value {$this.TotalItemSize -replace "(.*()|,| [a-z]*)", ""}
$UserMailboxStats |
   Select-Object DisplayName,@{Name="TotalItemSize (GB)"; `



   Moving from on-premises to the cloud with PowerShell (and PowerShell remoting in general) can sometimes present some new challenges due to what you have access to.  This means that you must always test your code / scripts.  I still believe that not having to physically RDP to a server is a huge gain over some of the small hurdles you may encounter during the transition.  Scripting is the future of administration and makes you more valuable.  Hopefully this script and the concepts presented help you be a better admin / developer.


      -Frog Out




The Get-MailboxStatistics Cmdlet, the TotalitemSize Property, and that pesky little “b”


View Mailbox Sizes and Mailbox Quotas Using Windows PowerShell


Regular Expressions with Windows PowerShell


“I don’t always test my code…” image


The One Thing: Brian Jackett and SharePoint 2010

2 thoughts on “Get Exchange Online Mailbox Size in GB

  1. Originally posted on: there,We have an hybrid exchange environment here. We have migrated half of the users to Office 365 and its all working fine.I would like to find who all are migrated to Office 365 and who all are still on exchange on premise?Could you please advise me how to do get the above details using power shell scripts or any other way?Thanks alot in Advance


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s