OU的LDAP查询

时间:2010-05-26 10:13:44

标签: c# active-directory ldap directoryservices

对不起是一个超级痛苦的人,这一切都很新:(

已经有很多帮助,但似乎无法看到问题,我正在尝试使用所有当前OU的列表填充组合框,稍后将该OU中的每台机器发送到shutdown命令。 (获取AD OU列表和Active Directory列表OU)是我以前的Q.

        string defaultNamingContext;
        //TODO 0 - Acquire and display the available OU's
        DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE");
        defaultNamingContext = rootDSE.Properties["defaultNamingContext"].Value.ToString();
        DirectoryEntry entryToQuery = new DirectoryEntry ("LDAP://" + defaultNamingContext);
        MessageBox.Show(entryToQuery.Path.ToString());

        DirectorySearcher ouSearch = new DirectorySearcher(entryToQuery.Path);
        ouSearch.Filter = "(objectCatergory=organizationalUnit)";
        ouSearch.SearchScope = SearchScope.Subtree;
        ouSearch.PropertiesToLoad.Add("name");

        SearchResultCollection allOUS = ouSearch.FindAll();

        foreach (SearchResult oneResult in allOUS)
        {
            //comboBox1.Items.Add(oneResult.ToString());
            comboBox1.Items.Add(oneResult.Properties["name"][0]);
        }

我已经完成并调试了我所知道的一切,搜索者没有收到任何结果,因此为什么组合框中没有填充任何内容。

2 个答案:

答案 0 :(得分:3)

  

我不得不使用非索引   objectClass而不是Catergory。

你只需要拼写正确: objectCategory - 不是objectCate r gory

(那里有一个“r”太多.....: - )

答案 1 :(得分:2)

作品:):)

我不得不使用非索引的objectClass而不是Catergory。

组合框已经完全填满了。

编辑: { “(objectClass的=组织单元)。” }

相关问题