Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top