title: Using C# to get Active Directory users which have at least a group starting with a specified value
body: <p>I have a <code>c#</code> application which uses <code>Active Directory</code>. I need to take all users which has at least a group starting with a specified value.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>using (PrincipalContext pcontext = new PrincipalContext(ContextType.Domain, "my-domain"))
  {
      UserPrincipal uspPrincipal = new UserPrincipal(pcontext);
  
      // Here I think is the problem
      uspPrincipal.GetGroups().Any(x =&gt; x.Name.StartsWith("my value"));
      PrincipalSearcher ps = new PrincipalSearcher(uspPrincipal);
      var results = ps.FindAll();
      var resMembers = results.Where(x =&gt; x is UserPrincipal)
              .Cast&lt;UserPrincipal&gt;()
              .Distinct()
              .Select(x =&gt; x.GivenName + ", " + x.Surname).ToList();
  } 
  </code></pre>
  
  <p>I receive a lot of users, but after I checked in <code>Active Directory</code> I found out that the number is bigger than expected result.</p>
  
  <p>I know that I can bring firstly the groups that starts with seached value and then I can take for each group it's users but this means a lot of queries in <code>Active Directory</code> and I want to bring my users using just one interogation in <code>Active Directory</code>, so can I obtain neded users with a single search? </p>