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 https://outlook.office365.com/powershell-liveid/ `
-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

10 replies »

  1. Edit: i had to convert the Itemsize from KB to MB. I’ve used this in the end:

    Get-Mailbox | Get-MailboxStatistics | Select-Object DisplayName, @{name=”TotalItemSize (MB)”;expression={[math]::Round((($_.TotalItemSize.Value.ToString()).Split(“(“)[1].Split(” “)[0].Replace(“,”,””)/1MB),2)}} | Sort “TotalItemSize (MB)” -Descending

    Like

  2. Hi, i get the list but it’s not in descending order. I have a Mailbox with 10MB, than 10GB, than 40GB and than 20MB again. I don’t get it to be sorted from smallest to biggest Mailbox. Same with “get-exomailboxstatistics”:

    Example:

    TotalItemSize
    ————-
    898.1 KB (919,668 bytes)
    15.75 GB (16,906,742,083 bytes)
    13.45 GB (14,437,253,993 bytes)
    5.944 GB (6,382,734,560 bytes)
    3.168 GB (3,401,572,316 bytes)
    4.626 GB (4,967,250,324 bytes)
    560 MB (587,252,036 bytes)
    4.19 GB (4,499,310,137 bytes)

    Like

  3. #Install-Module PowerShellGet -Force
    #Install-Module –Name ExchangeOnlineManagement
    Connect-ExchangeOnline

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

    Like

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

    “New-PSSession : [outlook.office365.com] Connecting to remote server outlook.office365.com 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

    Like

  5. 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

    Like

Leave a comment

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