gpt4 book ai didi

c# - OU 的 LDAP 查询

转载 作者:太空狗 更新时间:2023-10-29 23:19:05 26 4
gpt4 key购买 nike

很抱歉成为一个 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com