读/过滤通讯组的活动目录的群?通讯、目录

2023-09-09 21:38:13 作者:人潮拥挤~别丢了自己

我已经与域的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;
}