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.
To Augment the above I have knocked up an extension method to call ExtensionGet. It uses reflection to get hold of the protected method you would otherwise have to inherit. You might need to use this if you are returning UserPrincipalObjects from Groups.Members, for example
Yes, the default set of properties on
UserPrincipal
is quite limited - but the great part is: there's a neat extensibility story in place!You need to define a class descending from
UserPrincipal
and 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
ExtensionGet
andExtensionSet
methods 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
UserPrincipalEx
class instead ofUserPrincipal
:Read all about the
System.DirectoryServices.AccountManagement
namespace and its extensibility story here:Update: sorry - here's the
UserPrincipalExSearchFilter
class - missed that one in the original post. It just shows the ability to also extend the search filters, if need be: