0

Trying to get a list of users in a group. I can get users in an OU and stuff. But the group isn't working! I've since taken the group out of the OU and put it in the root hoping that would help, but it didn't.

CN=thisisthegroup,DC=thisisthedomain,DC=com

Any help would be appreciated, I'm very new to LDAP. Thanks.

Ber53rker
  • 669
  • 3
  • 10
  • 21

1 Answers1

1

you can try liek this

static void Main(string[] args)
{
    string groupName = "Domain Users";
    string domainName = "";

    PrincipalContext ctx = new PrincipalContext(ContextType.Domain, domainName);
    GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, groupName);

    if (grp != null)
    {
         foreach (Principal p in grp.GetMembers(false))
         {
                Console.WriteLine(p.SamAccountName + " - " + p.DisplayName);
         }

        grp.Dispose();
        ctx.Dispose();
        Console.ReadLine();
    }
    else
    {
        Console.WriteLine("\nWe did not find that group in that domain, perhaps the group resides in a different domain?");
        Console.ReadLine();
    }
}

or you can try that one specified in this link on How to get Users Belonging to Active Directory group

Glory Raj
  • 17,397
  • 27
  • 100
  • 203