Human Readable Mailbox Stats for All Mailboxes
The Get-EXOMailboxStatistics cmdlet only gets one mailbox at a time. When we want to get all Mailboxes statistics, we need to get all mailboxes first and store the response in a variable.
$Mailboxes = Get-EXOMailbox -ResultSize UnlimitedGet-EXOMailboxStatistics will return you the Total Item Count and Total Item Size, however the Total Item Size is not in a consistent set of units. If a mailbox is < 1GB, it'll display it in Megabytes instead of Gigabytes. This makes it rather painful when trying to do any form of analysis.
To get around this, we need to use a regex to capture the bytes value of the returned information. The regex we use to capture this is [0-9.]{0,} .{0,} (([0-9,]{0,}) bytes).
Select-String gives us an array of matches, of which we want the first match. Then we want the second Group of that match and then finally, get the value.
The first Group in the Match is the full string that matches the regex and subsequent strings are what match the capture group defined in the regex.
We then want to remove the commas (there is a way we could do this with another regex, but this also works) and then divide by 1GB so that regardless of the value we retrieved, it is divided by 1024 ^ 3.
The snippet to run in full is below.
```
$Mailboxes = Get-EXOMailbox -ResultSize Unlimited
$MailboxStats = $Mailboxes | Select displayname,primarysmtpaddress,RecipientTypeDetails,@{l='TotalItemSizeGB';e={
((((Get-EXOMailboxStatistics -Identity $_.Alias).TotalItemSize.Value `
| Select-String -Pattern '[0-9.]{0,} .{0,} \(([0-9,]{0,}) bytes\)').Matches[0].Groups[1].Value)).Replace(",","") / 1GB
}}
$MailboxStats | Format-Table -Auto
```This will give you a human readable list of Mailbox Sizes. You can amend the $MailboxStats line to include TotalItemSize if you wish.
Last updated