简体   繁体   中英

Search Users in Active Directory based on First Name, Last Name and Display Name

I trying to search my organization Active directory for users.

If the FirstName or LastName or DisplayName matches a particular string value, it should return the users.

My Code:

// create your domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

UserPrincipal qbeUser = new UserPrincipal(ctx);
qbeUser.GivenName = "Ramesh*";
// qbeUser.Surname = "Ramesh*";
// qbeUser.DisplayName= "Ramesh*";    

PrincipalSearcher srch = new PrincipalSearcher(qbeUser);

// find all matches
foreach(var found in srch.FindAll())
{
    //
}

The problem is that I am able to search by only one filter.

I am able to AND the filters but not OR. Whether any solutions are available?

See a possible solution for this issue in this other SO question .

You will need to use the extensibility of UserPrincipal to create a descendant class, in order to get access to the anr property (anr = ambiguous name resolution) which allows searches in multiple name-related properties at once.

Have a look at the DirectorySearcher. This article may help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM