UserPrincipal‘s FindByIdentity method allows me to search ActiveDirectory using username.
However, I also want to be able to search using user’s real name (e.g. Wayne, Bruce)
How can I do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use a
PrincipalSearcherand a “query-by-example” principal to do your searching:If you haven’t already – absolutely read the MSDN article Managing Directory Security Principals in the .NET Framework 3.5 which shows nicely how to make the best use of the new features in
System.DirectoryServices.AccountManagementUpdate:
Of course, depending on your need, you might want to specify other properties on that “query-by-example” user principal you create:
Surname(or last name)DisplayName(typically: first name + space + last name)SAM Account Name– your Windows/AD account nameUser Principal Name– your “username@yourcompany.com” style nameYou can specify any of the properties on the
UserPrincipaland use those as “query-by-example” for yourPrincipalSearcher.