Get members of some group

118 views Asked by At

I have a LDAP address to some group, such as LDAP://CN=Users,CN=Builtin,DC=tt, DC=s, DC=LOCAL How would I go about getting the users that belong to this group? Originally, I thought doing this would work:

    DirectoryEntry group = new DirectoryEntry("LDAP://CN=Users,CN=Builtin,DC=tt, DC=s, DC=LOCAL");
        foreach (object user in group.Properties["member"])
        {
            DirectoryEntry _user = new DirectoryEntry("LDAP://" + user);
            Console.WriteLine(_user.Properties["cn"].Value.ToString());
        }

However, this is not printing any of the members of the group. In fact, the foreach loop isn't even being executed, because it is not finding any members of the group. But when I look at the group in the database, it clearly has several members.

1

There are 1 answers

0
Nate B. On

I think the domain part is missing, even in the first DirectoryEntry object.

I use String.Format("LDAP://{0}/{1}", _dc, distinguishedName_) where dc is this domain part and where distinguishedName is your "object user" into string, in order to have something like

LDAP://dc1.corp.domain.com/OU=Service Accounts,OU=Corp Objects,DC=corp,DC=domain,DC=com

Check it out here.