0

是否有任何直接的方法可以让所有 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;
    }

请帮我解决这个问题。

提前致谢

4

1 回答 1

2

使用 (objectClass= organizationalUnit ) 而不是 (objectClass=organizational-Unit)

于 2013-08-05T07:24:21.347 回答