title: How do I search for a user in a particular OU on a remote LDAP server?
body: <p>I would like to use the <code>AccountManagement</code> namespace introduced in .NET 3.5 to find a user and set their password.  However, the ADLDS server is not part of our company domain so I'm using <code>ContextType.Machine</code>.  When I search for the user it's never found (I suspect it's searching in the wrong container, but according to the documentation when using <code>ContextType.Machine</code> you can't specify a container).</p>
  
  <pre><code>using (var context = new PrincipalContext(ContextType.Machine, "test-server", null, "username", "password")) {
      using (var u = UserPrincipal.FindByIdentity(context, "SuperAdmin")) {
          //u is always null.   :(
      }
  }
  </code></pre>
  
  <p>However, I know I can find the user using plain ol' <code>DirectoryEntry</code>:</p>
  
  <pre><code>using (var de = new DirectoryEntry("LDAP://test-server:389/CN=SuperAdmin,CN=SuperUsers,OU=test-server,DC=foo,DC=bar,DC=com", "username", "password", AuthenticationTypes.Secure)) {
      //The user is found, but SetPassword fails with "The directory property cannot be found in the cache"
      de.Invoke("SetPassword", new object[] { "foobar" });
  }
  </code></pre>
  
  <p>One last thing to point out is that I can use ADSI Edit to change the password with these same credentials.  Is it possible to use the newer directory objects to perform this search?</p>