0

The code I have correctly creates a list (results) with all users with a name containing James.

How can I change the code so that results will contain all users in the domain/ou?

        // create your domain context and define the OU container to search in
        PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "YYYYYY", "OU=XXXXXX,OU=ZZZZ Exchange");

        List<UserPrincipal> searchPrincipals = new List<UserPrincipal>();
        searchPrincipals.Add(new UserPrincipal(ctx) { Name = "*James*" });

        List<Principal> results = new List<Principal>();
        var searcher = new PrincipalSearcher();

        //add results to list
        foreach (var item in searchPrincipals)
        {
            searcher = new PrincipalSearcher(item);
            results.AddRange(searcher.FindAll()); ;
        }

If I try to return all results using wildcard like so, the list results is empty:

searchPrincipals.Add(new UserPrincipal(ctx) { Name = "**" });
Dawson
  • 457
  • 2
  • 9
  • 21

0 Answers0