OU的LDAP查询

Ste*_*rby 5 c# directoryservices ldap active-directory

对不起是一个超级痛苦的人,这一切都很新:(

已经有很多帮助,但似乎没有能够看到问题,我正在尝试使用所有当前OU的列表填充组合框,稍后将该OU中的每台机器发送一个关机命令.(获取AD OU列表和Active Directory列表OU)是我以前的Q.

        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]);
        }
Run Code Online (Sandbox Code Playgroud)

我已经完成并调试了我所知道的一切,搜索者没有获得任何结果,因此为什么组合框中没有填充任何内容.

mar*_*c_s 3

我不得不使用非索引对象类而不是类别。

您只需正确拼写:objectCategory - 不是 objectCate r gory

(你的“r”太多了......:-)