title: get all users from a group in Active Directory
body: <p>I'm trying to get all users of a particular group in AD, then return a list of Employees as mapped to properties in my Employee class. I have:</p>
  
  <p>My Filter is producing no results - what should it be?</p>
  
  <p>Also, I tried the first solution here:
  <a href="https://stackoverflow.com/questions/3195617/list-of-users-in-specific-active-directory-distribution-group">List of users in specific Active Directory Distribution Group</a>, but I need details such as mobile, extension, etc. which I couldn't get with that method.    </p>
  
  <pre><code>public static List&lt;Employee&gt; CreateEmployeeList(string department)
  {
      List&lt;Employee&gt; employees = new List&lt;Employee&gt;();
      string filter = string.Format("(&amp;(ObjectClass=person)(memberOf=CN={0},OU=Users &amp; Groups,OU=Blah,DC=Blah,DC=Blah,DC=Blah))", department);
  
      DirectoryEntry adRoot = new DirectoryEntry("LDAP://" + domain, null, null, AuthenticationTypes.Secure);
      DirectorySearcher searcher = new DirectorySearcher(adRoot);
      searcher.SearchScope = SearchScope.Subtree;
      searcher.ReferralChasing = ReferralChasingOption.All;
      searcher.Filter = filter;
      SearchResultCollection results = searcher.FindAll();
  
      foreach (SearchResult user in results)
      {
          // do whatever you need to do with the entry
  
          if (user != null)
          {
              UserDirectoryEntry = user.GetDirectoryEntry();
              string displayName = GetUserProperty("displayName");
              string firstName = GetUserProperty("givenName");
              string lastName = GetUserProperty("sn");
              string email = GetUserProperty("mail");
              string tel = GetUserProperty("telephonenumber");
              string extension = GetUserProperty("ipphone");
              string mobile = GetUserProperty("mobile");
              string title = GetUserProperty("description");
              employees.Add(new Employee{ FullName = displayName, FirstName = firstName, Surname = lastName, Email = email.ToLower(), Telephone = tel, Extension = extension, Mobile = mobile, JobTitle = title });
          }
      }
      return employees;
  }
  </code></pre>