The (&(objectClass=user)(|(&(SAMAccountName=jdoe*))) search filter is invalid.
I'm trying to locate John Doe's user account by his username, jdoe. I've used a number of variants of this search string, and they all return this error. What am I doing wrong? I'm building it out like this:
var deSearch = new DirectorySearcher(de);
deSearch.Filter = string.Format("(&(objectClass=user)(|(&(SAMAccountName={0}*)))", uname);
SearchResult result = deSearch.FindOne();
You need to close the opening parenthesis :
(&(objectClass=user)(|(&(SAMAccountName=jdoe*))))
If you are using .Net 3.5 or later, you can use a UserPrincipal object to get user information, like this.
PrincipalContext pcontext = new PrincipalContext(ContextType.Domain, domainName);
UserPrincipal user = UserPrincipal.FindByIdentity(pcontext,IdentityType.SamAccountName, "UserName");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With