0
是否有任何直接獲取所有OU進入Active Directory的方法? 我曾嘗試下面的代碼,我在從活動目錄獲取所有OU
ouSearch.FindAll()
越來越COM異常(操作無效)我的代碼如下所示。
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服務器) – MAC
好吧,只要確保LDAP://部分是**大寫**(不要使用ldap ://''或'Ldap://'或類似的東西..) –