I’ve successfully used the AccountManagement code to retrieve basic AD information but it’s only returning a very limited set of information about the returned object. How can I get extended information from AD using the AccountManagement functionality. Specifically the Job Title or title as it seems to be called in my instance of AD.
I know how to do it using the older DirectoryServices but I’d like to know how to do it using the new namespace.
Yes, the default set of properties on
UserPrincipalis quite limited – but the great part is: there’s a neat extensibility story in place!You need to define a class descending from
UserPrincipaland then you can very easily get access to a lot more properties, if needed.The skeleton would look something like this:
And that’s really almost all there is! The
ExtensionGetandExtensionSetmethods allow you to “reach down” into the underlying directory entry and grab out all the attributes you might be interested in….Now, in your code, use your new
UserPrincipalExclass instead ofUserPrincipal:Read all about the
System.DirectoryServices.AccountManagementnamespace and its extensibility story here:Update: sorry – here’s the
UserPrincipalExSearchFilterclass – missed that one in the original post. It just shows the ability to also extend the search filters, if need be: