C#PrincipalSearcher,返回AD组的特定OU [英] C# PrincipalSearcher, returning AD groups for specific OU

查看:376
本文介绍了C#PrincipalSearcher,返回AD组的特定OU的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一点难与此code,特别是与PrincipalSearcher。我试图让所有与特定OU相关联的组的列表。

I'm having a bit of difficultly with this code, specifically with PrincipalSearcher. I'm trying to get a list of all the Groups associated with a specific OU.

我想只返回在所有组作用域安全的群体,但不包括通讯组。

I'm trying to just return "Security" groups under all Group Scopes, excluding distribution groups.

我有是,它的返回这些内置的群体,除了一个人的,我打算返回的问题。

The issue I'm having is, it's returning these built-in groups in addition to the one's I'm intending to return.

HelpServicesGroup TelnetClients 管理员 用户 客人 打印操作员 备份操作员 复制 远程桌面用户 网络配置操作员 性能监视器用户 性能日志用户 分布式COM用户 域计算机 域控制器 架构管理员 企业管理员 证书发布者 域管理员 域用户 域来宾 组策略创建所有者 RAS和IAS服务器 服务器操作员 帐户操作员 pre-Windows 2000兼容访问 传入林信任建设者 Windows授权访问组 终端服务器许可证服务器 DNSADMINS DnsUpdateProxy IIS_WPG

HelpServicesGroup TelnetClients Administrators Users Guests Print Operators Backup Operators Replicator Remote Desktop Users Network Configuration Operators Performance Monitor Users Performance Log Users Distributed COM Users Domain Computers Domain Controllers Schema Admins Enterprise Admins Cert Publishers Domain Admins Domain Users Domain Guests Group Policy Creator Owners RAS and IAS Servers Server Operators Account Operators Pre-Windows 2000 Compatible Access Incoming Forest Trust Builders Windows Authorization Access Group Terminal Server License Servers DnsAdmins DnsUpdateProxy IIS_WPG

我不知道,如果可能的范围是不正确或也许我缺少某种过滤。

I'm not sure if perhaps the scope is incorrect or maybe I'm missing some sort of filtering.

相关code段:

    public static ArrayList GetAllGroups()
    {
        var myItems = new ArrayList();

        var ctx = new PrincipalContext(ContextType.Domain,"MyOU");

        // define a "query-by-example" principal - here, we search for a GroupPrincipal 
        var qbeGroup = new GroupPrincipal(ctx);

        // create your principal searcher passing in the QBE principal    
        var srch = new PrincipalSearcher(qbeGroup);

        // find all matches
        foreach (Principal found in srch.FindAll())
        {
            var foundGroup = found as GroupPrincipal;

            if (foundGroup != null)
            {
                myItems.Add(foundGroup.Name);
            }
        }
        return myItems;
    }

我如何得到这个排除内置组?

How do I get this to exclude the built-in groups?

任何与这一援助将大大AP preciated。

Any assistance with this will be greatly appreciated.

感谢您!

推荐答案

两件事情:

  1. 有没有团体的<​​em>相关的有一个OU - 一个OU是容器其中的包含的用户,计算机,组等。 (如包含文件的目录)。那是什么意思?你要列举组的包含一个给定的OU ??

  1. there are no groups associated with an OU - an OU is a container which contains users, computers, groups etc. (like a directory that contains files). Is that what you mean? You want to enumerate the group contained inside a given OU??

如果是这样:你不调用构造函数 PrincipalContext 正常。如果检查<一href="http://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.principalcontext.aspx">MSDN在 PrincipalContext 构造中,你会发现你正在使用的一个是一个具有 ContextType 名称这表示在域名:

if so: you're not calling the constructor for the PrincipalContext properly. If you check the MSDN documentation on PrincipalContext constructors, you'll see that the one you're using is the one with a ContextType and a name which stands for the domain name of the context you want to bind to:

var ctx = new PrincipalContext(ContextType.Domain,"MyOU");

这绑定到 MyOU 域 - 它正确绑定在该域树的根

This binds to the MyOU domain - and it binds right at the root of that domain tree.

什么,你可能寻找的是构造有三个参数 - 一个 ContextType 两个字符串 - 第一个是域名如上,而第二个是你的搜索的起始位置。所以,你的 PrincipalContext 结构更改为:

What you're probably looking for is the constructor with three parameters - a ContextType and two strings - the first one being the domain name as above, and the second one being the start location of your search. So change your PrincipalContext construction to:

var ctx = new PrincipalContext(ContextType.Domain, "YOURDOMAIN", "OU=MyOU");

然后搜索了 - 这是包含现在您应该只得到集团 OU = MyOU 容器内

and then search again - now you should get only groups that are contained inside the OU=MyOU container.

这篇关于C#PrincipalSearcher,返回AD组的特定OU的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆