如何使用C#获取域非内置组?
我有一个c#函数,它给出了所有域组的名称:如何使用C#获取域非内置组?,c#,active-directory,active-directory-group,C#,Active Directory,Active Directory Group,我有一个c#函数,它给出了所有域组的名称: public static List<String> ListAllDomainGroups() { List<String> groups = new List<string>(); // create your domain context PrincipalContext ctx = new PrincipalContext(ContextType.Domain); // d
public static List<String> ListAllDomainGroups()
{
List<String> groups = new List<string>();
// create your domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
// define a "query-by-example" principal - here, we search for a GroupPrincipal
GroupPrincipal qbeGroup = new GroupPrincipal(ctx);
// create your principal searcher passing in the QBE principal
PrincipalSearcher srch = new PrincipalSearcher(qbeGroup);
// find all matches
foreach (var found in srch.FindAll())
{
// do whatever here - "found" is of type "Principal" - it could be user, group, computer.....
//listBox2.Items.Add(found.ToString());
groups.Add(found.ToString());
}
return groups;
}
public静态列表ListAllDomainGroups()
{
列表组=新列表();
//创建域上下文
PrincipalContext ctx=新PrincipalContext(ContextType.Domain);
//定义一个“示例查询”主体-在这里,我们搜索一个GroupPrincipal
GroupPrincipal qbeGroup=新的GroupPrincipal(ctx);
//创建传递QBE主体的主体搜索者
PrincipalSearcher srch=新PrincipalSearcher(qbeGroup);
//查找所有匹配项
foreach(在srch.FindAll()中找到的变量)
{
//在这里做任何事情-“发现”属于“主体”类型-可能是用户、组、计算机。。。。。
//listBox2.Items.Add(find.ToString());
groups.Add(find.ToString());
}
返回组;
}
函数返回大约70个名称,包括:
WinRMRemoteWMIUsers
管理员
用户
客人
打印操作
备份操作员
Replicator
IIS\u IUSRS
远程桌面用户
。。。
(然后是我定义的组)
我如何才能只获得我在广告中定义的群而不获得内置群?好吧,我相信你有两个选择。第一个是msdn中指定的所有组。创建组的排除列表。第二个选项是基于SID进行修改。SID包含域SID部分和最后一个整数部分RID。DC将其递增并分配给安全主体。所以,我想默认组在每个域中应该有相同的rid。例如,理论上,您可以使用rid>某个数字查询对象。不确定它是否有效,但你可以检查一下