Before proceed, if you are working with normal PowerShell console instead of Exchange Management Shell, you need to run the following command to import exchange management powershell cmdlets.
Add-PSSnapin *Exchange*
Summary
- Get Mailbox Size for Single User
- Get Mailbox Size of All Users
- Export Mailbox Size Report to CSV
- Export Mailbox Size report with filter
Get Mailbox Size for Single User
The following command gets the mailbox size and total count of messages for the user ‘Morgan’.
Get-MailboxStatistics -Identity 'Morgan' | Select DisplayName,ItemCount,TotalItemSize
Get Mailbox Size of all the users and sorted by size
The following powershell script get a list of all the user’s mailbox size and sorted by size in Descending order, so that you
can easily find the users who are using high storage space in their mailbox.
Get-MailboxStatistics -Server 'ExchSVR1' | Where {$_.ObjectClass -eq “Mailbox”} | Sort-Object TotalItemSize -Descending | Select-Object -Property @{label=”User”;expression={$_.DisplayName}}, @{label=”Total Messages”;expression={$_.ItemCount}}, @{label=”Total Size (MB)”;expression={$_.TotalItemSize.Value.ToMB()}}, LastLogonTime
Export Mailbox Size Report to CSV
We can export powershell output into CSV file using Export-CSV cmdlet. The following powershell script export all the user’s mailbox size, total messages and lastLogon time values into CSV file.
Get-MailboxStatistics -Server 'ExchSVR1' | Where {$_.ObjectClass -eq “Mailbox”} | Select-Object -Property @{label=”User”;expression={$_.DisplayName}}, @{label=”Total Messages”;expression={$_.ItemCount}}, @{label=”Total Size (MB)”;expression={$_.TotalItemSize.Value.ToMB()}}, LastLogonTime | Export-CSV "C:\MailBoxSize-Report.csv" -NoTypeInformation -Encoding UTF8
CSV output of mailbox size report:
Export mailbox size report with filter
we can use the exchange powershell cmdlet Get-Mailbox to get specific set of mailbox enabled Active Directory users and pass user details to Get-MailboxStatistics cmdlet. You can apply filters in Get-Mailbox cmdlet to select users.
Get-Mailbox | Where {$_.DistinguishedName -like "*OU=TestOU,DC=TestDomain,DC=local*"} | Get-MailboxStatistics | Where {$_.ObjectClass -eq “Mailbox”} | Select-Object -Property @{label=”User”;expression={$_.DisplayName}}, @{label=”Total Messages”;expression={$_.ItemCount}}, @{label=”Total Size (MB)”;expression={$_.TotalItemSize.Value.ToMB()}}, LastLogonTime| Export-CSV "C:\MailBoxSize-Report.csv" -NoTypeInformation -Encoding UTF8