且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

查询PrincipalSearcher包含多个字符串

更新时间:2023-02-26 10:58:53

我是通过使用foreach循环来完成此操作的,但是以下代码仍未回答我关于如何为Principalsearcher进行操作的问题

I did this by using a foreach loop But the following code still doesn't answer my question on how to do it for Principalsearcher

var groups = new List<string>();
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
GroupPrincipal qbeGroup = new GroupPrincipal(ctx);
PrincipalSearcher srch = new PrincipalSearcher(qbeGroup);
    foreach (var group in srch.FindAll())
    {
       if (group.Name.Contains("Administrators") || group.Name.Contains("Users"))
       {
             groups.Add(group.Name);
       }
    }
return groups.ToArray();