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
#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