Re: Active directory: Get users associated with groups

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Marc Scheuner [MVP ADSI] (m.scheuner_at_inova.SPAMBEGONE.ch)
Date: 03/15/05


Date: Tue, 15 Mar 2005 08:25:51 +0100


>Hi, can anyone please tell me (Given a group name) how I can retrieve just
>those users associated with that group using Active Directory using LDAP??

Insepect the user's "memberOf" property

DirectoryEntry deUser = new DirectoryEntry("LDAP://......");

foreach(string sGroupName in deUser.Properties["memberOf"])
{
  Console.WriteLine(sGroupName);
}

This is the easy way of doing it - it will *NOT* show you the user's
"primary group", nor any nested groups. For those you'd need to
inspect the user object's "tokenGroups" attribute (which is a
collection of SID's), and then resolve those SIDs to group names.

Check out microsoft.public.adsi.general - there have been several
posts on how to read the full group membership by means of
"tokenGroups".

HTH
Marc

================================================================
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch



Relevant Pages

  • Re: LDAP - get groups user
    ... >which this user is member. ... >I am using the LDAP. ... Insepect the user's "memberOf" property ... inspect the user object's "tokenGroups" attribute (which is a ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Pure LDAP Authentication using vb.net
    ... Like I said, I don't know how to do group membership in Novell, so I don't ... Joe Kaplan-MS MVP Directory Services Programming ... Co-author of "The .NET Developer's Guide to Directory Services Programming" ... you will likely need to use something like LDAP simple bind. ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Determine AD group membership
    ... Other LDAP directories use groups as well. ... in other directories as the distinction between security-enabled groups and ... and would be doing LDAP for group membership lookups. ...
    (microsoft.public.platformsdk.security)
  • Re: Check group membership, the sequel
    ... > WindowsIdentity for the use with their userPrincipalName. ... You'll probably need to do some directory services code to do ... > the group membership expansion (although the AzMan APIs may be an option ... The secret with LDAP calls is to use the tokenGroups attribute ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Check group membership, the sequel
    ... > WindowsIdentity for the use with their userPrincipalName. ... You'll probably need to do some directory services code to do ... > the group membership expansion (although the AzMan APIs may be an option ... The secret with LDAP calls is to use the tokenGroups attribute ...
    (microsoft.public.dotnet.security)