Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LDAP Query for OU's

Sorry for being an uber pain people, its all very new :(

Already had alot of help on this, but don't seem to be able to see the problem, I am trying to populate a combo box with a list of all the current OU's, later to send each machine within that OU a shutdown command. (Acquiring AD OU list & Active Directory list OU's) were my previous Q's.

        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 been through and debugged everything i know, the searcher isn't picking up any results, hence why nothing is populated in the combo box.

like image 888
Stephen Murby Avatar asked May 26 '10 10:05

Stephen Murby


People also ask

What is an OU LDAP?

LDAP - Organizational unit (OU)The organizational unit attribute refers to the organizational unit (or sometimes the user group) that the user is part of. If the user is part of more than one group, you may specify as such, e.g., OU= Lawyer,OU= Judge.

What is DC and DN in LDAP?

dc. Domain Component. The AdsPath of an object in Active Directory (the binding string) consists of the provider moniker (LDAP://) appended to the Distinguished Name of the object. The Distinguished Name specifies not just the name of the object, but also its location in the Active Directory hierarchy.

What is DC OU?

DC objects represent the top of an LDAP tree that uses DNS to define its namespace. Active Directory is an example of such an LDAP tree. The designator for an Active Directory domain with the DNS name Company.com would be dc=Company,dc=com. Organizational Unit (OU). OU objects act as containers that hold other objects.


2 Answers

I have had to use the non indexed objectClass rather than Catergory.

You just need to spell it correctly: objectCategory - not objectCatergory

(you have an "r" too much in there..... :-)

like image 54
marc_s Avatar answered Sep 24 '22 22:09

marc_s


Works :) :)

I have had to use the non indexed objectClass rather than Catergory.

The combo box has populated perfectly fine now.

EDIT: { "(objectClass=organizationalUnit)" }

like image 29
Stephen Murby Avatar answered Sep 23 '22 22:09

Stephen Murby