I am using the following command to query the count of all security groups in our domain:
Get-ADGroup -Filter {name -notlike 'solution team iw'} | select name, @{n='Member Count' ; e= {(get-adgroupmember $_.samaccountname -recursive).count }} | export-csv C:\\adgroupmembercount.csv
However, the command fails on one group, Solution Team IW.
I am trying to exclude this group using the expression shown, but the command still returns the error “Invalid Enumeration Context”.
I’m guessing there’s a corrupt AD object. But I can’t remove this object as business operations depend on it.
I’ve tried specifying another domain controller, but no luck.
Any ideas on how you would workaround this issue?