title: How to get a UserPrincipal object for the manager from the employee's UserPrincipal object
body: <p>I have an Active Directory searcher to get users' details using <code>UserPrincipal</code> objects. I'm using <code>System.DirectoryServices</code> and <code>System.DirectoryServices.AccountManagement</code> and it's accessing AD through a context.</p>
  
  <p>However, I also need to get the user's manager as a separate <code>UserPrincipal</code> object. What would be the most direct way to go about this?</p>
  
  <p>I have tried the following but unfortunately the cast won't work:</p>
  
  <pre><code>DirectoryEntry directoryEntry = (DirectoryEntry)userPrincipal.GetUnderlyingObject();
  UserPrincipal manager = (UserPrincipal)directoryEntry.Properties["manager"][0];
  </code></pre>
  
  <p>I hoped there would be a <code>UserPrincipal</code> property called <code>UsersManager</code> inside every UserPrincipal object but I'm unable to find this so I'm guessing there's no such thing.</p>
  
  <p>Thanks!</p>