Exchange Powershell 2007/2010 Mailbox Audit

I'm trying to perform an audit of mailboxes in Exchange output to a Format Table with the following columns:
- Organizational Unit
- Display Name
- Database
- Mailbox Size
- Deleted Items Size
- Item Count

The Org Unit can only be pulled from Get-Mailbox and the rest of the data from Get-MailboxStatistics. My current script is here:
 
$OU = Get-Mailbox $_.OrganizationalUnit; 
Get-MailboxStatistics -Server <ServerName> | Sort-Object -property @{Expression="DatabaseName";Descending=$False},
@{Expression="TotalItemSize";Descending=$true} | ft OrganizationalUnit,DisplayName,DatabaseName,@{label="Mailbox Size(MB)";expression=
{$_.TotalItemSize.Value.ToMB()}},@{label="Del Items Size (MB)";expression={$_.TotalDeletedItemSize.Value.TOMB()}},ItemCount -GroupBy DatabaseName

Open in new window



It pulls all of the data from Get-MailboxStatistics, but not the Org Unit info from Get-Mailbox. This is probably the 17th iteration of this script and I can't get the Org Unit to be pulled into the table. Any help would be appreciated.

LVL 1
citsloginAsked:
Who is Participating?
 
prashanthdCommented:
Try the following...
Get-MailboxStatistics -Server <ServerName> | Sort-Object -property @{Expression="DatabaseName";Descending=$False},@{Expression="TotalItemSize";Descending=$true} | ft @{label="OrganizationalUnit";expression={(get-mailbox $_).OrganizationalUnit}},DisplayName,DatabaseName,@{label="Mailbox Size(MB)";expression={$_.TotalItemSize.Value.ToMB()}},@{label="Del Items Size (MB)";expression={$_.TotalDeletedItemSize.Value.TOMB()}},ItemCount -GroupBy DatabaseName

Open in new window

0
 
citsloginAuthor Commented:
Awesome! It works beautifully, thanks! I had tried something along the lines of this previously, but the placement of the parenthesis was not something I was aware of, so kept failing out. Again, thanks so much!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.