Powershell Script to Find The Largest Mailbox in Exchange Server

Tej Pratap Shukla | Modified: October 16, 2024 | Exchange Server, General Info | 6 Minutes Reading

Both admins and regular users struggle to find the largest mailbox in the Exchange server. This is quite a serious issue if admins have forgotten to place a size nearing limit alert at the time of mailbox creation.

The Exchange server won’t allow users to receive or even send any mail. Putting a stop to all email communication. So if multiple users are about to face this problem admins can’t go to the EAC and check for each user one by one which very well may number in the thousands.

That’s why we have put together a few PowerShell scripts to show mailbox size statistics. Use them and identify them as soon as possible.

How to Find the Largest Mailbox?

As a user, you do not just want to find the largest mailbox in the Exchange server but do so via a simplified Power-shell script. That is why we present a PowerShell script that will show the user mailbox whose size is the largest.

Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited | 
Get-MailboxStatistics | 
Sort-Object TotalItemSize -Descending | 
Select-Object DisplayName, TotalItemSize, ItemCount -First 1

get-mailboxstatistics mailbox size in mb

Note: If two mailboxes have the same size, the order will be arbitrary and not deterministic. As in PowerShell, when sorting by a single property and there are ties, the remaining order is determined by the internal sorting algorithm
To ensure deterministic sorting in case of ties, you can specify additional properties in the Sort-Object cmdlet.

Use PowerShell Script to Show Mailbox Size Statistics for All Users

As you saw earlier the most important command that lets us explore the Exchange mailbox data is

Get-MailboxStatistics

find largest mailbox in Exchange

However, it alone is not sufficient for what we want to accomplish.

If you try to run it on your EMS you will be asked for an Index value, which is nothing but the user name whose data you want to collect. You won’t get the size parameter.

That’s why we need to make additional changes in the script to get the name of a mailbox, the number of items and the mailbox storage limit.

Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited | Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | Select-Object DisplayName, TotalItemSize, ItemCount

find mailbox size

This will give you a descending-order list of the most important components name, size, and item count. Note in our script we filter out the user mailboxes specifically, if you want data for all mailboxes (i.e. archive, shared, etc) use the following instead.

Get-MailboxDatabase | Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | Select-Object DisplayName, TotalItemSize, ItemCount

Now, you need not append the format-table or ft command here as our script puts the data in tabular form by default.

What Are The Causes Behind Mailbox Sizes Too Large?

There can be various reasons that can prevent the Exchange Server mailbox size limit from being over-sized. The main cause of the Exchange Server mailbox is:

#1 The major reason will be the Exchange migration process if users focus Exchange server having a larger message size than the previous one. It is possible to modify these limits.

#2 Also, in the case of Exchange online the message size is final as per Microsoft’s Official documents.

It is a well-known fact that large mailboxes are a primary reason why admins need to repair corrupt databases in Exchange 2016 or other versions.

Find The Largest Mailbox in Exchange and Get-MailboxStatistics Mailbox Size in GB

If use mailbox size swells up too much viewing it in megabytes won’t show the full picture. Moreover, it is impossible to maintain the bigger size of the mailbox in the user Exchange mailbox account without creating a complex Powershell script that connects to Exchange using EWS.

Launch the EMS or a PowerShell with a remote Exchange connection then type the following

Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited | 
Get-MailboxStatistics | 
Select-Object DisplayName, @{Name="TotalItemSizeGB";Expression={$_.TotalItemSize.Value.ToGB().ToString("F3")}}, ItemCount | 
Sort-Object TotalItemSizeGB -Descending | 
Export-Csv -Path "C:\path\to\your\report.csv" -NoTypeInformation

Note: If the user’s in-place archive is not showing in Outlook 2013 you may have to build a report of their mailbox size.

As per the result, the report.csv file will appear in Drive C which includes a list of the largest mailbox folders with subject and size until a user can customize the above script even further. Like restricting the search to only those results whose file size exceeds a specific 25MB threshold.

Another Note: The user can customize the above script in multiple ways, for example, to change the above-mentioned 25MB size in Where-Object { $_.TopSubjectSize -gt 25MB}part will apply a contrary message size to the filter. Replace Get-Mailbox -ResultSize Unlimited with Get-Mailbox-Identity Administrator helps to search limited Administrator’s mailbox.

After executing the script on the Command prompt, the resulting CSV file will become in this form:
Mailbox Statistics List According to Size

Conclusion

In this write-up, we educated the admins on how exactly to use PowerShell and show mailbox size. Thus making the task of finding the largest mailbox in the Exchange Server quite easy. The scripts present here can help locate and report all user mailboxes whose sizes are nearing their maximum capacity. After which they can implement size management techniques. Like creating an online archive or exporting the old Exchange data via the SysTools EDB to PST converter

Download Now Free Purchase Now 100% Secure

and clearing the user mailbox.

Frequently Asked Questions on How to Use PowerShell for Showing User Mailbox Data in Exchange?

Do I need special privileges to use PowerShell and show the mailbox size in Exchange Server?
Yes as this is an admin-level task only users with said permissions will be able to perform it. Although, super admins can delegate special permissions to users after which they will also be able to use the same scripts.

Is it possible to use the regular PowerShell instance or do I strictly need the Exchange Management Shell?
Yes, you can very well use the regular PowerShell, just make sure to establish a connection with the Exchange server.

How can I export the mailbox list I see in Shell space?
Simply append the Export-CSV -path C:/your/intended/destination/*.csv -NoTypeInformation at the end of the script.

Other than PowerShell what can I use to see the mailbox size in Exchange?
You can use the EAC > Go to Recipients > Under the Mailboxes tab > select a user > click on the pencil(edit icon)
A new edit user mailbox window opens there to toggle the mailbox usage option. You will be able to see how much of the total mailbox is full in a pictorial graph.

get mailbox size data without PowerShell