I’m using the following code to get the members of a group on my domain:
Dim de As New DirectoryEntry('LDAP://' & GroupDN) For Each user As String In CType(de.Properties('member'), IEnumerable) GroupCollection.Add(Username, Username) Next
My problem is that when GroupDN (the distinguishedname of the group) is ‘CN=Domain Users,CN=Users,DC=Mydomain,DC=local‘, the For…Each loop doesn’t execute, and when I check the Properties statement manually, it’s got a count of zero. This seems to work for every other group in my domain, but the ‘Domain Users’ group should contain everybody, and it appears to contain nobody.
I’ve checked, and the group lists everybody correctly in my Windows AD tools. Is there something obvious that I’m missing here? On a side note, is there a better way to get all the members of a group?
Unless you change the primary group id of a user, the user is not stored in the member attribute of the Domain Users group, rather it uses the fact that the primary group id is set to the Domain Users RID to determine membership in Domain Users. The normal case is that the Domain Users member attribute is empty; it would require that you make some changes to the default Active Directory implementation for this to not be the case.
Reference