【问题标题】:Getting All OUs from a Active Directory从 Active Directory 获取所有 OU
【发布时间】:2013-05-29 09:36:39
【问题描述】:

是否有任何直接的方法可以让所有 OU 进入 Active Directory? 我试过下面的代码,我在

处得到 Com Exception (Invalid operation)
ouSearch.FindAll()

我的代码如下所示。

public static List<string> GetAllOus(string ldapServer, string ldapUserName, string ldapPassWord)
    {

        List<string> orgUnits = new List<string>();
        string defaultNamingContext;

        DirectoryEntry rootDSE = new DirectoryEntry(ldapServer + "/dc=server-dc,dc=com", ldapUserName, ldapPassWord, AuthenticationTypes.Anonymous);
        //defaultNamingContext = rootDSE.Properties["defaultNamingContext"].Value.ToString();

        //DirectoryEntry defaultentry = new DirectoryEntry("LDAP://" + defaultNamingContext);

        DirectorySearcher ouSearch = new DirectorySearcher(rootDSE,
                                             "(objectClass=organizational-Unit)",
                                             null, SearchScope.Subtree);

        foreach (SearchResult resEnt in ouSearch.FindAll())
        {
            string OUName = resEnt.GetDirectoryEntry().Name;
            orgUnits.Add(OUName);
        }

        return orgUnits;
    }

请帮我解决这个问题。

提前致谢

【问题讨论】:

  • 你的ldapServer有什么价值??
  • @marc_s:它包含像 LDAP://192.168.2.5(AD 服务器)这样的值
  • 好的,只要绝对确保LDAP:// 部分是大写的(不要使用ldap://Ldap:// 或类似的东西......)跨度>
  • 我认为你应该使用 (objectClass=organizationalUnit) 而不是 (objectClass=organizational-Unit)。
  • ya.. 完全大写。

标签: c# asp.net active-directory ou


【解决方案1】:

使用 (objectClass=organizationalUnit) 代替 (objectClass=organizational-Unit)

【讨论】:

    猜你喜欢
    • 2019-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多