是否有任何直接的方法可以让所有 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;
}
请帮我解决这个问题。
提前致谢