Trying to get a count of mailboxes assigned to a retentionpolicy

Environment- MS Exchange 2010

We have about 10 Retention Policies in our environment and I would like to get a count of the number of mailboxes assigned to each policy.  Here is the script I thought should do the trick, but didn't.

get-mailbox -resultsize unlimited| group-object -property:RetentionPolicy| sort-object Count -desc| select RetentionPolicy, Count

I have also tried -

get-mailbox -resultsize unlimited| group-object -property RetentionPolicy| sort-object Count -desc| select RetentionPolicy, Count

As I have seen this syntax as well.  I have also tried running these scripts as Administrator to make sure that wasn't the issue.

While the count column gets populated the retention policy column is simply blank for all policies.  When I remove the group-object section the script does populate the retention policy column, but ungrouped.  The only thing I can think of is that the group-object doesn't like grouping by retention policy, though why this would be I can't fathom.

Can anyone straighten out this puzzle?

TIA

August 19th, 2015 10:50am

Have you tried selecting the properties first then group them?

get-mailbox -resultsize unlimited | select RetentionPolicy, Count | group-object -property RetentionPolicy | sort-object Count -desc
I do not have these cmdlet's so I cannot test
Free Windows Admin Tool Kit Click here and download it now
August 19th, 2015 10:54am

Thanks Clayman2.  This worked.  

Lesson learned - if it doesn't work one way shake things up and see what happens then.

August 19th, 2015 11:43am

In case it helps someone in the future here is the final script for counting and grouping mailboxes and retention policies.

get-mailbox -resultsize unlimited| select RetentionPolicy, count| group-object -property RetentionPolicy| sort-object count -desc| ft Name, Count


Free Windows Admin Tool Kit Click here and download it now
August 19th, 2015 11:51am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics