title: C# PrincipalSearcher, returning AD groups for specific OU
body: <p>I'm having a bit of difficultly with this code, specifically with PrincipalSearcher. I'm trying to get a list of all the Groups associated with a specific OU. </p>
  
  <p>I'm trying to just return "Security" groups under all Group Scopes, excluding distribution groups.</p>
  
  <p>The issue I'm having is, it's returning these built-in groups in addition to the one's I'm intending to return.</p>
  
  <p>HelpServicesGroup
  TelnetClients
  Administrators
  Users
  Guests
  Print Operators
  Backup Operators
  Replicator
  Remote Desktop Users
  Network Configuration Operators
  Performance Monitor Users
  Performance Log Users
  Distributed COM Users
  Domain Computers
  Domain Controllers
  Schema Admins
  Enterprise Admins
  Cert Publishers
  Domain Admins
  Domain Users
  Domain Guests
  Group Policy Creator Owners
  RAS and IAS Servers
  Server Operators
  Account Operators
  Pre-Windows 2000 Compatible Access
  Incoming Forest Trust Builders
  Windows Authorization Access Group
  Terminal Server License Servers
  DnsAdmins
  DnsUpdateProxy
  IIS_WPG</p>
  
  <p>I'm not sure if perhaps the scope is incorrect or maybe I'm missing some sort of filtering.</p>
  
  <p>The relevant code segment: </p>
  
  <pre><code>    public static ArrayList GetAllGroups()
      {
          var myItems = new ArrayList();
  
          var ctx = new PrincipalContext(ContextType.Domain,"MyOU");
  
          // define a "query-by-example" principal - here, we search for a GroupPrincipal 
          var qbeGroup = new GroupPrincipal(ctx);
  
          // create your principal searcher passing in the QBE principal    
          var srch = new PrincipalSearcher(qbeGroup);
  
          // find all matches
          foreach (Principal found in srch.FindAll())
          {
              var foundGroup = found as GroupPrincipal;
  
              if (foundGroup != null)
              {
                  myItems.Add(foundGroup.Name);
              }
          }
          return myItems;
      }
  </code></pre>
  
  <p>How do I get this to exclude the built-in groups?</p>
  
  <p>Any assistance with this will be greatly appreciated.</p>
  
  <p>Thank you!</p>