You must Sign In to post a response.
  • Category: WCF

    How to get the specific AD group from the LDAP using System.DirectoryServices

    I want to get the specific AD group from the LDAP for the given user name.
  • #767890
    If you're on .NET 3.5 or newer, you can use a PrincipalSearcher and a "query-by-example" principal to do your searching:
    you can do it using following code snippet

    // create your domain context
    PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

    // define a "query-by-example" principal - here, we search for a GroupPrincipal
    GroupPrincipal qbeGroup = new GroupPrincipal(ctx);

    // create your principal searcher passing in the QBE principal
    PrincipalSearcher srch = new PrincipalSearcher(qbeGroup);

    // find all matches
    foreach(var found in srch.FindAll())
    {
    // do whatever here - "found" is of type "Principal" - it could be user, group, computer.....
    }

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]


  • Sign In to post your comments