locked
Security group vs Distribution group RRS feed

  • Question

  • User1396448631 posted

    I found the following piece of code which lists all the AD groups from here

    http://stackoverflow.com/questions/9487517/how-to-query-active-directory-for-all-groups-and-group-members

    // 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())
     {
         GroupPrincipal foundGroup = found as GroupPrincipal;
    
         if(foundGroup != null)
         {
            // do whatever you need to do, e.g. put name into a list of strings or something
         }
     }

    I would like to know if there is anyway we can find if the groups listed are security or distribution groups?

    Thank you

    Tuesday, May 31, 2016 3:14 PM

All replies