Merging/Joining Get-aduser, Get-mailbox, and Get-mailboxstatistics

Exchange mailbox reporting often takes more than one command. I needed mailbox details, mailbox size and department information in a single extract, so this example combines the results.

Validate a sample first

For Exchange mailbox reporting, check the join field before running the report across the organisation. Compare a few sample rows against the original commands and investigate blank department or size values before sharing the file.

A laptop displays a fictional mailbox report beside server hardware.

The other day, I was asked to provide an extract of all mailboxes in my exchange environment, along with attributes only available in other PS commands.

The below script provides the list (Get-Mailbox)along with a the sizes (Get-MailboxStatistics) and users’s associated dept(Get-User).

Hope it helps you.

Get-Mailbox -resultsize unlimited | sort-object | Select-Object DisplayName,PrimarySmtpAddress,@{n=”Size(KB)”;e = {$MBXstat = Get-MailboxStatistics $_.name; $MBXstat.totalItemsize}}, @{n=”ItemAcount”;e = {$MBXstat = Get-MailboxStatistics $_.name; $MBXstat.itemcount}},@{n=”Dept”;e={(get-aduser $_.name -properties department).department}} | export-csv mailboxout.csv

Related reading on this site: Automated PowerShell Script for Updating UserPrincipalNames in Active Directory After Domain Change.

Leave a Reply

Your email address will not be published. Required fields are marked *