I use the code snippet below from System.DirectoryServices.AccountManagement
to search for user in ActiveDirectory.
The user.Name
returns successfully, but how can I retrieve other properties from AD for the user, like msExchRecipientTypeDetails
since it is not displayed in VisualStudio 2015 intelligence?
using (PrincipalContext adPrincipalContext = new PrincipalContext(ContextType.Domain, DOMAIN, USERNAME, PASSWORD))
{
UserPrincipal userPrincipal = new UserPrincipal(adPrincipalContext);
userPrincipal.SamAccountName = "user-ID";
PrincipalSearcher search = new PrincipalSearcher(userPrincipal);
foreach (var user in search.FindAll())
{
Console.WriteLine("hei " + user.Name);
// how to retrive other properties from AD like msExchRecipientTypeDetails??
}
}