title: User not listed in AD Search
body: <p>I am developing a program in C# that searched all of the users in AD and adds them to a list. Unfortunately, I have run across a case in which a particular user is not being added to the group.</p>
  
  <p>Relevant code I am using to create the list (in a try/catch block):</p>
  
  <pre><code>List&lt;User&gt; ADUsers = new List&lt;User&gt;();
  string domainPath = "LDAP://DC=domain,DC=local";
  search.Filter = "(&amp;(objectClass=user))";
  //I was including propertiesToLoad here, but I removed it in testing
  SearchResultCollection results = search.FindAll();
  if (results != null)
    {
      foreach (SearchResult result in results)
      {
        if (result.Properties.Contains("samaccountname") &amp;&amp; result.Properties.Contains("mail") &amp;&amp; result.Properties.Contains("displayname"))
        {
          User objSurveyUser = new User((String)result.Properties["samaccountname"][0], (String)result.Properties["mail"][0], (String)result.Properties["displayname"][0]);
          ADUsers.Add(objSurveyUser);
        }
      }
    }
  return ADUsers;
  </code></pre>
  
  <p>I get 900+ entries (as expected), and I have so far been able to search for every user I have tried but one. </p>
  
  <p>I checked in AD to verify that the user was classified as a user, so I know it should no be getting filtered out. I also verified (in hyena) that the Pre-2k accountname (samaccountname), email address (mail), and display name were all listed and correct for this user.</p>
  
  <p>I have created else blocks to catch users that are missing one or more of the above and tried to find the user that way, but to no avail.</p>
  
  <p>Does anyone see anything obvious that I might be missing in my code?</p>
  
  <p><strong>Update:</strong> I changed the search filter to <code>(objectCategory=person)</code> and some of the users I was unable to find appeared. Getting closer.</p>
  
  <p><strong>Update 2:</strong> I think there might be an issue with the way AD Searcher works. I changed <code>(objectCategory=person)</code> to <code>(|(objectCategory=person)(objectClass=user))</code>. By the rules of logic, my returned size should grow; instead, it shrinks. <code>|A U B| &gt;= |A|</code></p>
  
  <p><strong>Update 3:</strong> I have entirely removed the line for <code>search.filter</code> and tried a different filter: <code>(!(userAccountControl=2))</code>. Both options give me the complete list of users in the base OU, but they do not search inside other OUs.</p>