Invalid Enumeration Context with Get-ADGroupMember

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of Greg Tate Greg Tate 5 months, 4 weeks ago.

  • Author
    Posts
  • #42650
    Profile photo of Greg Tate
    Greg Tate
    Participant

    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?

  • #42654
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Have you tried just running the initial Get command to confirm that the group is being excluded from the results?

  • #42656
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    Hi Greg,
    Take a look at this article on Technet Wiki to see if it helps. I suspect, after looking at your code, you are running into this same issue.

    http://social.technet.microsoft.com/wiki/contents/articles/32418.active-directory-troubleshooting-server-has-returned-the-following-error-invalid-enumeration-context.aspx

  • #42695
    Profile photo of Greg Tate
    Greg Tate
    Participant

    Curtis,
    You saved the day!

    This article helped me understand the issue (and taught me a new skill along the way with using TCPView in conjunction with measure-command).

    Ultimately, I was able to get the command to work by reducing the ResltPageSize from default 256 to a smaller number, 25.

You must be logged in to reply to this topic.