c# - OU 的 LDAP 查询

标签 c# active-directory ldap directoryservices

很抱歉成为一个 super 痛苦的人,这一切都是新的:(

在这方面已经有很多帮助,但似乎看不出问题所在,我正在尝试用所有当前 OU 的列表填充一个组合框,稍后向该 OU 中的每台机器发送一个关机命令。 (获取 AD OU 列表和 Active Directory 列表 OU)是我以前的问题。

        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]);
        }

我已经检查并调试了我所知道的一切,搜索器没有找到任何结果,因此组合框中没有填充任何内容。

最佳答案

I have had to use the non indexed objectClass rather than Catergory.

您只需要正确拼写:objectCategory - 而不是 objectCatergory

(你的“r”太多了......:-)

关于c# - OU 的 LDAP 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2911962/

相关文章:

ldap - 有没有免费的带数据的 LDAP 服务器?

用于查询 LDAP 的 Java API

C# 反射 - 在运行时确定依赖项的位置

c# - 在 C# 中动态实例化遗留 COM 对象(在字符串中使用其 ID)

c# - 我可以在不知道 Active Directory (AD) 中 OU 的情况下通过某些属性获取特定用户吗?

为创建 AD 帐户编写了 Java 代码,但发生 LDAP 异常

c# - 记录-改变实现?

c# MVC 4 Web API - 从 JSON 字符串返回对象

active-directory - Keycloak:将用户从一个用户联盟迁移到另一个用户联盟

java - 如何使用 JNDI 在 java 中强制执行 LDAP bindRequest?