title: LDAP-Search in 2 organizational units
body: <p>Due to some changes on AD-level I have to change a lookup in AD in my application. The search must now be executed in 2 different OU instead of 1.</p>
  
  <p>At this moment I run a second search if the first one returns nothing.</p>
  
  <p>Is it possible to combine the 2 paths into 1 so have to search only once?</p>
  
  <p>Thx.</p>
  
  <pre><code>using (var de = new DirectoryEntry())
  {
      de.Path = "LDAP://OU=ou1,OU=Users,OU=BE,DC=dc,DC=sys";
      de.AuthenticationType = AuthenticationTypes.Secure;
  
      var deSearch = new DirectorySearcher
      {
          SearchRoot = de,
          Filter = "(&amp;(objectClass=user) (sAMAccountName=" + userId + "))"
      };
  
      var result = deSearch.FindOne();
  
      if (result == null)
      {
          //User not found in ou1
          de.Path = "LDAP://OU=ou2,OU=Users,OU=BE,DC=dc,DC=sys";
          de.AuthenticationType = AuthenticationTypes.Secure;
  
          deSearch = new DirectorySearcher
          {
              SearchRoot = de,
              Filter = "(&amp;(objectClass=user) (sAMAccountName=" + userId + "))"
          };
  
          result = deSearch.FindOne();
  
          if (result==null) return null;
      }
  
      using (var deUser = new DirectoryEntry(result.Path))
      {
          //Do something
      }
  }
  </code></pre>