Microsoft 365

Microsoft 365: List User Mailboxes sorted by Mailbox Size

In this blog post I will show you how you can get a list of your Microsoft 365 Exchange Online recipients sorted by size. I am a documentation geek so it’s not a surprise that I always striving to have a good overview of user mailbox sizes and storage usage.

Connect to Exchange Online

First of all we need to connect to Exchange Online. Hit the keys and enter the following lines to connect to your tenant.

$Session = New-PSSession -ConfigurationName Microsoft.Exchange `
-ConnectionUri `
-Credential (Get-Credential) -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking 

How do you know that worked? You should see this screen:

Anmerkung 2020-04-04 092638

Retrieve a list of Microsoft 365 Mailboxes sorted by Mailbox Size

Next, run the code below to get a list of all user mailboxes sorted by size in descending order.

Get-Mailbox -RecipientTypeDetails UserMailBox -ResultSize Unlimited |
Get-MailboxStatistics |
Where-Object {!$_.DisconnectDate} |
Sort-Object -Property TotalItemSize -Descending |
Select-Object DisplayName,ItemCount,TotalItemSize,LastLogonTime

Anmerkung 2020-04-06 093925.png

Fine. That’s it. Mission accomplished.

See also

Microsoft 365: Show Mailboxes that have Auto-Reply enabled

Microsoft 365: Add User Accounts and Mailboxes with PowerShell

8 replies »

  1. #Install-Module PowerShellGet -Force
    #Install-Module –Name ExchangeOnlineManagement

    Get-EXOMailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited | Get-EXOMailboxStatistics | Select-Object Displayname, TotalItemSize, MailboxGuid | Sort-Object TotalItemSize -Descending


  2. Hi Patriick, thanks for sharing. when i am trying to authentication, i am getting access denied. I have global administrator access.

    “New-PSSession : [] Connecting to remote server failed with the following error message : Access is denied. For more
    information, see the about_Remote_Troubleshooting Help topic.
    At line:1 char:12
    + $Session = New-PSSession -ConfigurationName Microsoft.Exchange `
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : OpenError: (System.Manageme….RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
    + FullyQualifiedErrorId : AccessDenied,PSSessionOpenFailed


  3. Hi.

    For a big organisation, is there a way to stop this from timing out? Also, how would you include the online archive as an extra column?

    Many thanks


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 )

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.