I'm trying to generate a mailbox report for our hosted Exchange platform and automate things a bit. Basically each tenant is in an OU. So I'm trying to first pull a list of OU's, then count the mailboxes in each OU. Here's what I have so far:
$ous = (Get-ADOrganizationalUnit -SearchBase "OU=Microsoft Exchange Hosted Organizations,DC=yomamma,DC=com" -Filter { (ObjectClass -eq 'organizationalunit') -and (Name -notlike 'Hosted Organization Security Groups') -and (Name -Notlike 'Microsoft Exchange Hosted Organizations') })
foreach ($ou in $ous) {
(Get-Mailbox -Organization $ou.Name -Filter {( Name -notlike 'Administrator' -and Name -notlike 'DiscoverySearch*' )} -ResultSize unlimited).count
}
It works... sort of. The result will be a ton of numbers on each line, a mailbox count for each OU. Problem is, then I have OU's in the $ous variable, and I'm outputting the count to the screen. What I need is output two columns, the OU, alongside the count in another column, so I can pipe it into Export-CSV cmdlet so I can have client name (OU), and the count in a CSV file to them email.
I'm just not sure how to get that combination of data all at once.