title: Get only users who belong to a specific group
body: <p>I'm trying to understand Active Directory as quickly as I can, but so far I haven't been very successful. I have this code that returns all the users from AD which somebody else wrote and I'm supposed to alter it so that it only returns the users for a specified group. I've tried to learn a little bit more about AD in the hopes that the solution will present itself, but no luck so far. So maybe someone can help me out? Here's the code that I have.</p>
  
  <pre><code>adSearch.Filter = "(&amp;(objectClass=user))";
  string groupName = System.Configuration.ConfigurationManager.AppSettings["ADGroupName"];
  string domain = adSearch.SearchRoot.Properties["dc"].Value.ToString();
  DomainLabel.Text = domain + " accounts:";
  foreach (SearchResult sResultSet in adSearch.FindAll())
  {
      if (!GetProperty(sResultSet, "givenName").Equals("") &amp;&amp; !GetProperty(sResultSet, "sn").Equals(""))
      {
          string userAccountControl = GetProperty(sResultSet, "useraccountcontrol");
          bool x = userAccountControl.Equals("512") || userAccountControl.Equals("66048");
          if (x)
          {
  
             ListItem tempItem = new ListItem();
             unsortedList.Add(GetProperty(sResultSet, "givenName") + " " + GetProperty(sResultSet, "sn"));
             tempItem.Text = GetProperty(sResultSet, "givenName") + " " + GetProperty(sResultSet, "sn");
             tempItem.Value = GetProperty(sResultSet, "sAMAccountName");
             values.Add(tempItem);
  
          }
      }
  }
  </code></pre>