Given a particular group with a lot of members, I want to query within the group to find members that have a DisplayName match.
The code below is a non-functional example of what I'd like to accomplish. Note that I don't want to load the whole list first then apply the 'where', I can already do that and it is slow because the group is large.
public static List<Principal> FindUsersOfGroup(string groupName, string displayNameQuery)
{
using (var context = new PrincipalContext(ContextType.Machine, Environment.MachineName))
{
var search = new GroupPrincipal(context);
search.SamAccountName = groupName;
// This where doesn't work, but is what I'm looking for.
search.Members.Where(m => m.DisplayName == displayNameQuery + "*");
using (var ps = new PrincipalSearcher(search))
{
// Want to get all members that match the query AND belong to the group.
return ps.FindAll().ToList();
}
}
}
Also, the context is Domain in my real code, I replaced it on purpose.