Export a CSV list of all the mailboxes with names and sizes in a fully numeric format, so they can be ordered, summed, etc. The script works on Office365 and on-prem servers as well.
Get-Mailbox -Filter {name -notlike "DiscoverySearchMailbox*"} -ResultSize unlimited | %{
$upn = $_.UserPrincipalName
# Calculate size
$size = ((Get-MailboxStatistics $upn).totalitemsize.value.tostring().split("( ")[3].replace(",",""))
# Size in GB
$sizeGB = $size/[math]::pow(1024,3)
# Print on the screen and export it to AllMailboxSizes.csv
write-host "$mb`t---`t$size bytes`t---`t$sizeGB GB"
[pscustomobject]@{Mailbox=$upn; "Size(byte)"=$size; "Size(GB)"=$sizeGB} | export-csv AllMailboxSizes.csv -append
}
The output of the csv file is as follows:


Comments