title: Get an Extension Attribute from AD?
body: <p>I got this from a member of our Network Team:</p>
  
  <p><img src="https://i.stack.imgur.com/9XLIN.png" alt="enter image description here"></p>
  
  <p>You can see that extensionAttribute2 has a value in it.  How can I retrieve this value - I cannot see extensionAttributes anywere in UserPrincipal object - unless I am missing something.</p>
  
  <p>I have went back a level further and tried the below:</p>
  
  <pre><code>        UserPrincipal myUser = UserPrincipal.FindByIdentity(con, identityName);
  
          DirectoryEntry de = (myUser.GetUnderlyingObject() as DirectoryEntry);
  
          if (de != null)
          {
              // go for those attributes and do what you need to do
              if (de.Properties.Contains("extensionAttribute2"))
              {
                  return de.Properties["extensionAttribute2"][0].ToString();
              }
              else
              {
                  return string.Empty;
              }
          }
  </code></pre>
  
  <p>However this does not work - debugging this there are about 40 properties available but none for extensionAttribute2</p>