title: Active directory check if user belongs to a group
body: <p>I am using the below code to pull active directory groups. How can I find out if a user belongs to xyz group or not?</p>
  
  <pre><code>// 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.....          
  }
  </code></pre>