How do I sort my mailbox statistics in O365?

Viewed 105

I am using the following code and I want to sort by TotalItemSize. I am not getting the desired results.

Get-Mailbox -RecipientTypeDetails usermailbox -resultsize 10 |
Get-MailboxStatistics | Sort-Object totalitemsize |
Format-Table totalitemsize
  • This results in the following:
TotalItemSize
-------------
22.7 GB (24,370,512,818 bytes) 
15.95 GB (17,130,688,417 bytes)
7.84 GB (8,417,699,591 bytes)
8.659 GB (9,297,263,477 bytes)
27.36 GB (29,374,899,586 bytes)
11.29 GB (12,119,583,472 bytes)
2.103 GB (2,258,067,401 bytes)
44.15 GB (47,409,766,670 bytes)
21.08 GB (22,629,885,399 bytes)
17.97 GB (19,296,711,234 bytes)
1 Answers

Try using this:

Get-Mailbox -RecipientTypeDetails usermailbox -Resultsize 10 |
Get-MailboxStatistics |
Sort-Object { [double][regex]::Matches($_.totalitemsize,'(?<=\()[\d,]+').Value } |
Format-Table totalitemsize

This is my poor attempt at regex please bare with me.

Once we capture the bytes and convert them to double with [regex]::Matches(...), Sort-Object should be able to handle it:

@'
22.7 GB (24,370,512,818 bytes) 
15.95 GB (17,130,688,417 bytes)
7.84 GB (8,417,699,591 bytes)
8.659 GB (9,297,263,477 bytes)
27.36 GB (29,374,899,586 bytes)
11.29 GB (12,119,583,472 bytes)
2.103 GB (2,258,067,401 bytes)
44.15 GB (47,409,766,670 bytes)
21.08 GB (22,629,885,399 bytes)
17.97 GB (19,296,711,234 bytes)
'@ -split '\r?\n' |
Sort-Object { [double][regex]::Matches($_,'(?<=\()[\d,]+').Value }

2.103 GB (2,258,067,401 bytes)
7.84 GB (8,417,699,591 bytes)
8.659 GB (9,297,263,477 bytes)
11.29 GB (12,119,583,472 bytes)
15.95 GB (17,130,688,417 bytes)
17.97 GB (19,296,711,234 bytes)
21.08 GB (22,629,885,399 bytes)
22.7 GB (24,370,512,818 bytes) 
27.36 GB (29,374,899,586 bytes)
44.15 GB (47,409,766,670 bytes)
Related