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:
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
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
Categories: Microsoft 365, PowerShell
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
LikeLike
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)
LikeLike
#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
LikeLike
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
“
LikeLike
i think found solution here https://docs.microsoft.com/en-us/exchange/troubleshoot/connecting-to-the-service/access-denied-connect-powershell
testing right now,
LikeLike
still access denied
LikeLike
ok…If you have Azure MFA enable, first part of authentication will not work, cause access denied, even you are global admin.
you need to install “Exchange admin center in Exchange Online”, instruction is here https://docs.microsoft.com/en-us/powershell/exchange/exchange-online/connect-to-exchange-online-powershell/mfa-connect-to-exchange-online-powershell?view=exchange-ps
once installed, use Connect-EXOPSSession to connect.
then, use 2nd part from here (Retrieve a list of Microsoft 365 Mailboxes sorted by Mailbox Size) to get information.
hope this will hope
LikeLike
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
LikeLike
Does it really timed out? I am surprised
LikeLike
Use the new get-exomailboxstatistics
LikeLike