To retrieve the size or item count of mailboxes, you must use the Get-MailboxStatistics or, even better, the improved Get-EXOMailboxStatistics PowerShell CmdLet.
Both PowerShell commands are part of the Exchange PowerShell module, ‘ExchangeOnlineManagement,’ which you can install using the following command:
Install-Module ExchangeOnlineManagement
After the Exchange management module is installed, you can start retrieving the size and item count of mailboxes.
By far, the best option is to use the new Get-EXOMailboxStatistics as it offers two obvious benefits:
- First, it only retrieves essential mailbox statistics (improved performance).
- Second, it can easily convert the size value to Bytes, KBs, MBs, and GBs.
The following output shows some basic usage of the Get-EXOMailboxStatistics command:
PS C:\> Get-EXOMailboxStatistics hans.c.orsted@azure.skrubbeltrang.com DisplayName : Hans Christian Ørsted MailboxGuid : b960c39b-1e76-4332-816b-5925f269da37 DeletedItemCount : 19 ItemCount : 241 TotalDeletedItemSize : 96.8 KB (99,121 bytes) TotalItemSize : 64.29 MB (67,411,850 bytes) PS C:\> (Get-EXOMailboxStatistics hans.c.orsted@azure.skrubbeltrang.com).TotalItemSize.Value 64.29 MB (67,411,850 bytes) PS C:\> (Get-EXOMailboxStatistics hans.c.orsted@azure.skrubbeltrang.com).TotalItemSize.Value.ToMB() 64 PS C:\> (Get-EXOMailboxStatistics hans.c.orsted@azure.skrubbeltrang.com).TotalItemSize.Value.ToGB() 0
As you notice in the last line, there are no digits provided. So, if you want to list mailbox sizes in GB with a number of digits, you’ll have to do some tweaking.
The following example grabs the TotalItemSize in bytes and converts it to GB with three digits:
PS C:\> [math]::Round((Get-EXOMailboxStatistics hans.c.orsted@azure.skrubbeltrang.com).TotalItemSize.Value.ToBytes()/[math]::Pow(1024, 3), 3) 0.063
Get the Mailbox Size of a Single User
By far, the easiest way to retrieve the mailbox usage of a single user is by using Easy365Manager.
Easy365Manager is a snap-in to Active Directory Users & Computers that consolidate AD and Office 365 management.
Easy365Manager provides two extra tabs (‘Office 365’ and ‘Mailbox’) in user properties that allows you to view and manage your Office 365 mailbox:
Easy365Manager saves you the trouble of constantly logging in to the many ever-changing web consoles provided by Microsoft.
It also lets you perform changes that normally require PowerShell scripting, like calendar delegation or Azure AD Connect synchronization.
Finally, with Easy365Manager, you can safely remove your on-premises Exchange Server, which instantly eliminates a significant burden (and potential risk) from your network.
Download the fully functional 30-day trial here.
You can install Easy365Manager to any PC or server running AD Users & Computers.
Easy365Manager makes no changes to your infrastructure and only takes a few minutes to install and configure.
Get the Mailbox Sizes of Multiple Users
To retrieve the mailbox sizes of multiple users, you should use the Get-EXOMailboxStatistics command.
As mentioned, it performs better than Get-MailboxStatistics and easily converts mailbox sizes to any format you want.
However, I suggest that you always export the size value as bytes. It’s the ‘purest’ value, and you can always convert it in Excel to your desired format.
(if you prefer to output the result in MB or GB, use the conversion method listed previously).
$Mbxs = Get-EXOMailbox -ResultSize Unlimited
$j = $Mbxs.Count
$Result = @()
For ($i = 0; $i -lt $j; $i++){
$Stats = $Mbxs[$i] | Get-EXOMailboxStatistics
$MbxInfo = [PSCustomObject] @{
UPN = $Mbx.UserPrincipalName
DisplayName = $Stats.DisplayName
TotalItemSize = $Stats.totalitemsize.value.ToBytes()
ItemCount = $Stats.ItemCount
TotalDeletedItemSize = $Stats.TotalDeletedItemSize.value.ToBytes()
}
$Pct = [int]($i / $j * 100)
Write-Progress -Activity "Retrieving stats." -Status "$Pct% Complete:" -PercentComplete ($Pct)
$Result += $MbxInfo
}
Write-Host
$Result | ft UPN,DisplayName,TotalItemSize,ItemCount,TotalDeletedItemSize -AutoSize
As the result is stored in a PowerShell object ($Result), you can easily export the result to a CSV file or use it for further automation:
PS C:\> $Result | Export-Csv c:\Temp\MailStats.csv -NoTypeInformation PS C:\> $Result | % {Write-Host Mailbox of $_.DisplayName has $_.ItemCount items.} Mailbox of App Mailbox has 2578 items. Mailbox of Customer Support has 241 items. Mailbox of Hans Christian Ørsted has 9634 items. ...