title: DirectorySearcher: How to get only entries for "real" users
body: <p>I use a <code>DirectorySearcher</code> to get all users from Active Directory - but I need to get only "real" users.</p>
  
  <p>Filter:</p>
  
  <pre><code>search.Filter = "(&amp;(objectClass=user)(objectCategory=person))";
  </code></pre>
  
  <p>but I get all user accounts, like:</p>
  
  <pre><code>henry.miller            &lt;-wanted
  ernest.hemingway        &lt;-wanted
  HealthMailboxced7671    &lt;-not wanted 
  </code></pre>
  
  <p><strong>Question:</strong> how does my filter need to be modified to return only <em>real</em> users?</p>
  
  <p>My whole code:</p>
  
  <pre><code>string DomainPath = "LDAP://DC=writers,DC=local";
  DirectoryEntry searchRoot = new DirectoryEntry(DomainPath);
  DirectorySearcher search = new DirectorySearcher(searchRoot);
  search.Filter = "(&amp;(objectClass=user)(objectCategory=person))";
  search.PropertiesToLoad.Add("samaccountname");
  
  SearchResult result;
  
  SearchResultCollection resultCol = search.FindAll();
  
  if (resultCol != null)
  {
      for (int counter = 0; counter &lt; resultCol.Count; counter++)
      {
          result = resultCol[counter];
  
          if (result.Properties.Contains("samaccountname"))
          {
              Console.WriteLine((String)result.Properties["samaccountname"][0]);
          }
      }
  }
  </code></pre>