读/过滤通讯组的活动目录的群? [英] Reading/Filtering Distribution Group's Subgroups of an active directory?

查看:154
本文介绍了读/过滤通讯组的活动目录的群?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经与域的Active Directory myDomain.local ,其下存在一个通讯组包含许多团体。
我怎样才能读取(编程)所有这些子组来检索他们的名字的列表?
而如何优化查询来筛选结果,这样它只是检索所有以单词结束小组区域
顺便说一句,我使用C#.NET,ASP.Net和SharePoint,我没有经历过与AD。

I've an Active Directory with domain myDomain.local, under it there exists a Distribution Group that contains many groups.
How can I read (programmatically) all these subgroups to retrieve a list of their names ?
And how to optimize the query to filter the result so that it just retrieves all the groups that ends with the word Region ?
BTW, I'm using C#.Net, ASP.Net and sharepoint, and i'm not experienced with AD.

推荐答案

这是我提出的解决方案;对于那些有兴趣谁:

Here's the solution I made; for those who are interested:

public ArrayList getGroups()
{
    // ACTIVE DIRECTORY AUTHENTICATION DATA
    string ADDomain = "myDomain.local";
    string ADBranchsOU = "Distribution Group";
    string ADUser = "Admin";
    string ADPassword = "password";

    // CREATE ACTIVE DIRECTORY ENTRY 
    DirectoryEntry ADRoot 
        = new DirectoryEntry("LDAP://OU=" + ADBranchsOU
                             + "," + getADDomainDCs(ADDomain),
                             ADUser, 
                             ADPassword);

    // CREATE ACTIVE DIRECTORY SEARCHER
    DirectorySearcher searcher = new DirectorySearcher(ADRoot);
    searcher.Filter = "(&(objectClass=group)(cn=* Region))";
    SearchResultCollection searchResults = searcher.FindAll();

    // ADDING ACTIVE DIRECTORY GROUPS TO LIST
    ArrayList list = new ArrayList();
    foreach (SearchResult result in searchResults)
    {
        string groupName = result.GetDirectoryEntry().Name.Trim().Substring(3);
        list.Add(groupName);
    }
    return list; 
}

public string getADDomainDCs(string ADDomain)
{
    return (!String.IsNullOrEmpty(ADDomain)) 
        ? "DC=" + ADDomain.Replace(".", ",DC=") 
        : ADDomain;
}

这篇关于读/过滤通讯组的活动目录的群?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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