Home Contact

The Frog Pond of Technology

Ripples of Knowledge for SharePoint and Other .Net Technologies


My blog has moved to WordPress at BrianTJackett.com. Any pages will automatically redirect to the new address in 7 seconds. Still working on the homepage redirects.

 Subscribe to this blog

About Me

Brian T. Jackett
Columbus, OH

Find me on...

Tag Cloud


Post Categories


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 Documents\All 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 Documents\All 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


Thursday, June 28, 2012 10:48 AM


# re: Get Exchange Online Mailbox Size in GB

Very helpful, saved time working out a script for myself. Thanks for sharing! 6/21/2013 11:42 AM | Douglas Plumley

# Mail box Info

Hi 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 5/4/2016 10:35 PM | Pramod

Post A Comment