We are often required to check mailbox size and storage quota for every user’s mailbox. In this post, we will explore how to find mailbox size and usage status using PowerShell, and find users who are going to reach their mailbox storage quota.
We can use the Get-MailboxStatistics cmdlet to get mailbox size and other mailbox statistics data. This cmdlet is available for both Exchange On-Premises server and Exchange Online (Microsoft 365).
Before you start, install the Exchange Online PowerShell V2 module and run the below command to connect Exchange Online Powershell.
Connect-ExchangeOnline
Run the below command to get mailbox statistics for a single user.
Get-MailboxStatistics -Identity "[email protected]" |
Select DisplayName, TotalItemSize, StorageLimitStatus, ItemCount
The field StorageLimitStatus indicates whether the user is above or below the storage limit. The field TotalItemSize shows the total size of a mailbox in bytes, we need to convert this size into MB or GB to make the value user-friendly.
Get-MailboxStatistics -Identity "[email protected]" |
Select DisplayName, @{n="Total Size (MB)";e={[math]::Round(($_.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)}}, StorageLimitStatus
Find Mailbox Size for all Microsoft 365 users
You can use the Powershell cmdlet Get-Mailbox to get all the mailboxes and pipe the results into the Get-MailboxStatistics cmdlet to get mailbox size for all users.
Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox | Get-MailboxStatistics |
Select DisplayName, @{n="Total Size (MB)";e={[math]::Round(($_.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)}}, StorageLimitStatus
Find the Size for all Shared Mailboxes
We need to set SharedMailbox to the RecipientTypeDetails parameter to retrieve the shared mailboxes.
Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails SharedMailbox | Get-MailboxStatistics |
Select DisplayName, @{n="Total Size (MB)";e={[math]::Round(($_.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)}}, StorageLimitStatus
Export Mailbox Size, Quota, and Storage Limit Status Report to CSV
The below PowerShell script first gets all user mailboxes and retrieves mailbox statistics for all mailboxes one by one. Finally, exports the mailbox name, primary and alias smtp email addresses, current mailbox usage size (TotalItemSize), storage warning quota (IssueWarningQuota), maximum size limit (ProhibitSendQuota), and size limit status (StorageLimitStatus) to a CSV file
$Result=@()
#Get all user mailboxes
$mailboxes = Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox
#Get all shared mailboxes
#$mailboxes = Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails SharedMailbox
$totalmbx = $mailboxes.Count
$i = 0
$mailboxes | ForEach-Object {
$mbx = $_
#Get mailbox statistics
$mbs = Get-MailboxStatistics -Identity $mbx.Identity
$i++
Write-Progress -activity "Processing $mbx" -status "$i out of $totalmbx completed"
if ($mbs.TotalItemSize -ne $null){
$size = [math]::Round(($mbs.TotalItemSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2)
}else{
$size = 0 }
$Result += New-Object -TypeName PSObject -Property $([ordered]@{
Name = $mbx.DisplayName
PrimarySmtpAddress = $mbx.PrimarySmtpAddress
AliasSmtpAddresses = ($mbx.EmailAddresses | Where-Object {$_ -clike 'smtp:*'} | ForEach-Object {$_ -replace 'smtp:',''}) -join ';'
TotalSizeInMB = $size
SizeWarningQuota=$mbx.IssueWarningQuota
StorageSizeLimit = $mbx.ProhibitSendQuota
StorageLimitStatus = $mbs.ProhibitSendQuota
})
}
$Result | Export-CSV "C:\Temp\MailboxSizeReport.csv" -NoTypeInformation -Encoding UTF8
Thank you!
In response to this post, Could you do one to get the size and status of online archive mailboxes?
Hi Daniel, please refer to the below post to get the size and status of online archive mailboxes.
https://morgantechspace.com/2021/01/check-size-and-status-of-archive-mailbox-powershell.html
In response to this post, Could you do one to get the size and status of room mailboxes?
You can just change the UserMailbox to RoomMailbox in the RecipientTypeDetails parameter.
Get-Mailbox -ResultSize Unlimited –RecipientTypeDetails RoomMailbox
Great script. I adapted it to my needs. Saved me time.
Thanks.