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

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 $; $MBXstat.totalItemsize}}, @{n=”ItemAcount”;e = {$MBXstat = Get-MailboxStatistics $; $MBXstat.itemcount}},@{n=”Dept”;e={(get-aduser $ -properties department).department}} | export-csv mailboxout.csv