Category Archives: Servers

Grouping Mailboxes with PowerShell

Here is a snip-it of PowerShell Code I am using to group and count the number of mailboxes on an Microsoft Exchange Server 2008 using CustomAttribute1.

On our server we have a unique ID stored in the CustomAttribute1 for mailboxes that belong to different groupings. For example in the CustomAttribute1 we store the company ID, in CustomAttribute2 we may store the service level they pay for. We found the need to keep a count of the number of mailboxes belonging to different companies.

$CountMembers = @{}
Get-Mailbox | foreach-object {$CountMembers[$_.CustomAttribute1]++}
$CountMembers

Naturally from here we can append the | Out-File Report.txt to save to a txt file. Ideally I would like to export to a csv, however this data format doesn’t support that. I may look further into this in the future.

We can use this method to group mailboxes by any common attribute actually. Say the count the number of mailboxes on each database using $_.Database