## Tuesday, April 14, 2015

### Categorize Mailbox Sizes In Buckets

We are starting to plan for our migration to Exchange 2013. As part of the process we are running through the calculator. One of the steps for this report are to categorize your users.  "10% 100mb mailboxes, 50% 500mb users, etc.. " Sure... I could simply create a series of IF THEN statements..

ForEach Mailbox in this group
IF MailboxSize <= 500mb THEN LT500++
IF MailboxSize > 500mb and Mailbox <= 1GB then GT500++
...

But where's the elegance in that? All I want is a count of mailbox sizes, I don't care to know what the actual sizes are for this report.

Then I was working on an issue and found this mount point space script. This gave me an idea.. I could use expressions to count for me.. So, the idea being, I would do a simple query "Get-MailboxStatistics" and feed it to a formula to do all the math for me.

```#Initialize the HASHTABLE.
\$hash = @{}
\$hash["lt 500mb"]=0
\$hash["500 to 1gb"]=0
\$hash["le 5gb"]=0
\$hash["gt 5gb"]=0

#Create the expressions to do the counting..
\$FiveH = @{Expression={\$msize=[math]::Round(\$_.sizebytes /1mb);if (\$msize -le 512) {\$hash["lt 500mb"]++}}}
\$Thou = @{Expression={\$msize=[math]::Round(\$_.sizebytes /1mb);if (\$msize -ge 513 -and \$msize -lt 1024) {\$hash["500 to 1gb"]++}}}
\$TwoThou = @{Expression={\$msize=[math]::Round(\$_.sizebytes /1mb);if (\$msize -ge 1024 -and \$msize -lt 5120) {\$hash["le 5gb"]++}}}
\$FiveThou = @{Expression={\$msize=[math]::Round(\$_.sizebytes /1mb);if (\$msize -gt 5120 ) {\$hash["gt 5gb"]++}}}

#Now for the heavy lifting, We run all the mailboxes through the calculations..
Get-mailboxDatabase NWSALES-* | Get-mailboxstatistics | select @{name="SizeBytes";Expression={\$_.totalitemsize.value.tobytes()}} | select \$FiveH,\$thou,\$TwoThou,\$FiveThou
```
When it runs, it doesn't display anything useful. Simply a bunch of blank lines. I suppose I could have it echo the current value at the end, but that isn't necessary. After about 30seconds to a minute, I get back to the PS prompt. The final result of the script is the Hash Table \$HASH.

Name Value
---- -----
gt 5gb 223
le 5gb 1169
500 to 1gb 670
lt 500mb 2109

With this, I can see half this population is under 500mb, but with another fairly large population between the 1gb to 5gb size.