Skip to content

How to get mailbox size greater than in Microsoft 365

How to get mailbox size greater than in Microsoft 365? You want to list mailboxes greater than a specific size. It comes in handy if you like to know which mailboxes are filling up fast or almost reaching the maximum limit. This article will show you how to get mailboxes over a certain size.

Get mailbox size greater than in Exchange on-premises

The Comparison Operators in PowerShell let you specify conditions for comparing values and finding values that match specified patterns. There are a lot of operators. The comparison operator that we will use is the operator -gt, and it stands for greater than.

List all mailboxes in Exchange on-premises greater than 50 GB in size. Again, this is in Exchange on-premises.

Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Where-Object { $_.TotalItemSize -gt "50GB" } | Select-Object DisplayName, ItemCount, TotalItemSize | Sort-Object TotalItemSize -Descending 

The output appears as below.

DisplayName ItemCount TotalItemSize
----------- --------- -------------
Info           122916 59.07 GB (63,423,330,124 bytes)
Marketing      134123 56.02 GB (60,094,747,890 bytes)

Let’s see how it looks in Exchange Online (Microsoft 365).

Connect to Exchange Online PowerShell

You have to Connect to Exchange Online PowerShell first. Run PowerShell as administrator and run the below command.

Connect-ExchangeOnline -UserPrincipalName admin@exoip.com

After that, check if you did connect succesfully to Exchange Online. An excellent way is to run the Get-EXOMailbox cmdlet and list five mailboxes.

Note: Make use of the EXO cmdlets when connected to Exchange Online. It will retrieve the data faster, and we recommend using it.

Get-EXOMailbox -ResultSize 5 | Select-Object DisplayName

The output will only output 5 mailboxes.

DisplayName
-----------
Amanda Morgan
Jonathan Fisher
Piers Rees
Benetiz Anees
Larson Tevin

Get mailbox size greater than in Microsoft 365 error

Let’s run the same command with the Get-Mailbox cmdlet as in Exchange on-premises, this time in Exchange Online (Microsoft 365).

Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Where-Object { $_.TotalItemSize -gt "50GB" } | Select-Object DisplayName, ItemCount, TotalItemSize | Sort-Object TotalItemSize -Descending 

Or with the new and improved cmdlets Get-EXOMailbox and Get-EXOMailboxStatistics

Get-EXOMailbox -ResultSize Unlimited | Get-EXOMailboxStatistics | Where-Object { $_.TotalItemSize -gt "50GB" } | Select-Object DisplayName, ItemCount, TotalItemSize | Sort-Object TotalItemSize -Descending 

After pressing Enter, the output gives us the following errors.

  • Error: Cannot convert value to type
  • Error: Operation is not valid due to the current state of the object.
Could not compare "1.491 MB (1,563,034 bytes)" to "50GB". Error: "Cannot convert value "50GB" to type
"Microsoft.Exchange.Management.RestApiClient.Unlimited`1[Microsoft.Exchange.Management.RestApiClient.ByteQuantifiedSize]". Error: "Operation is not valid due to the current state of the object.""
At line:1 char:81
+ ... MailboxStatistics | Where-Object {$_.TotalItemSize -gt "50GB"} | Sort ...
+                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : ComparisonFailure

What is the solution to the errors, and how to get mailbox size greater than in Microsoft 365?

Solution for get mailbox total item size error in Microsoft 365

The error happens in Exchange Online because the TotalItemSize property is a string that includes the size and unit “1.491 MB (1,563,034 bytes)”, and you are trying to compare it directly to the string “50GB”, which is causing a type mismatch.

The solution to this error is to convert the TotalItemSize to a numerical value and then compare it to the size threshold.

Get all mailboxes greater than

Use the below command to get all mailboxes in Microsoft 365 with a size greater than 50 GB. Adjust the size to your needs.

Get-EXOMailbox -ResultSize Unlimited | Get-EXOMailboxStatistics | Where-Object { $_.TotalItemSize.Value.ToBytes() -gt "50GB" } | Select-Object DisplayName, ItemCount, TotalItemSize | Sort-Object TotalItemSize -Descending

The mailboxes appear in the output.

DisplayName    ItemCount TotalItemSize
-----------    --------- -------------
HR                100695 71.84 GB (77,135,813,741 bytes)
Sales              56826 66.25 GB (71,135,800,362 bytes)
James Paterson    187451 64.34 GB (69,088,700,819 bytes)
Info              236743 50.62 GB (54,354,792,583 bytes)

Get all shared mailboxes greater than

If you only want to get shared mailboxes greater than 50 GB.

Get-EXOMailbox -RecipientTypeDetails SharedMailbox -ResultSize Unlimited | Get-EXOMailboxStatistics | Where-Object { $_.TotalItemSize.Value.ToBytes() -gt "50GB" } | Select-Object DisplayName, ItemCount, TotalItemSize | Sort-Object TotalItemSize -Descending

The output shows the shared mailboxes.

DisplayName ItemCount TotalItemSize
----------- --------- -------------
HR                100695 71.84 GB (77,135,813,741 bytes)
Sales              56826 66.25 GB (71,135,800,362 bytes)
Info              236743 50.62 GB (54,354,792,583 bytes)

That’s it!

Note: Do you want to have a report of all the mailbox sizes in Exchange on-premises or Exchange Online (Microsoft 365)? Read the article Get mailbox size of all users in Exchange with PowerShell.

Keep reading: Move mailbox to Exchange Online with PowerShell »

Conclusion

You learned how to get mailbox size greater than in Microsoft 365. First, connect to Exchange Online PowerShell and run the correct command to get the results. The PowerShell comparison operator greater than is excellent to use.

Did you enjoy this article? You may also like Outlook prompts for password after migration to Office 365. Don’t forget to follow us and share this article.

ALI TAJRAN

ALI TAJRAN

ALI TAJRAN is a passionate IT Architect, IT Consultant, and Microsoft Certified Trainer. He started Information Technology at a very young age, and his goal is to teach and inspire others. Read more »

This Post Has 4 Comments

    1. Change the comparison -lt and value “50GB” to your needs.

      For example:

      This will show mailboxes greater than 10MB:

      Get-EXOMailbox -ResultSize Unlimited | Get-EXOMailboxStatistics | Where-Object { $_.TotalItemSize.Value.ToBytes() -gt "1MB" } | Select-Object DisplayName, ItemCount, TotalItemSize | Sort-Object TotalItemSize -Descending

      This will show mailboxes less than 1000KB:

      Get-EXOMailbox -ResultSize Unlimited | Get-EXOMailboxStatistics | Where-Object { $_.TotalItemSize.Value.ToBytes() -lt "1000KB" } | Select-Object DisplayName, ItemCount, TotalItemSize | Sort-Object TotalItemSize -Descending

Leave a Reply

Your email address will not be published. Required fields are marked *