Using PrincipalSearcher to find users with "or" parameters
.net, active-directory, c#
Solution
It's obviously not possible, here is a workaround:
List<UserPrincipal> searchPrinciples = new List<UserPrincipal>();
searchPrinciples.Add(new UserPrincipal(context) { DisplayName="tom*"});
searchPrinciples.Add(new UserPrincipal(context) { SamAccountName = "tom*" });
searchPrinciples.Add(new UserPrincipal(context) { MiddleName = "tom*" });
searchPrinciples.Add(new UserPrincipal(context) { GivenName = "tom*" });
List<Principal> results = new List<Principal>();
var searcher = new PrincipalSearcher();
foreach (var item in searchPrinciples)
{
searcher = new PrincipalSearcher(item);
results.AddRange(searcher.FindAll());
}
Problem
Is it possible to use `System.DirectoryServices.AccountManagement.PrincipalSearcher` to search based on multiple parameters using "or" (not "and"). i.e. ``` // This uses an and //(&(objectCategory=person)(!UserAccountControl:1.2.840.113556.1.4.803:=2)(&(SAMAccountName=tom*)(DisplayName=tom*))) var searchPrinciple = new UserPrincipal(context); searchPrinciple.DisplayName = "tom*"; searchPrinciple.SamAccountName = "tom*"; var searcher = new PrincipalSearcher(); searcher.QueryFilter = searchPrinciple; var results = searcher.FindAll(); ``` and I would like a search similar to this (in LDAP) using `PrincipalSearcher` (not `DirectorySearcher`) ``` // (&(objectCategory=person)(!UserAccountControl:1.2.840.113556.1.4.803:=2)(|(SAMAccountName=tom*)(DisplayName=tom*))) ```