views:

162

answers:

2

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.

+1  A: 

Works :) :)

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

The combo box has populated perfectly fine now.

EDIT: { "(objectClass=organizationalUnit)" }

Stephen Murby
+1 For finding the answer to your question all by yourself, and to provide it to the others who could be searching for such either. While using the DirectorySearcher class, always provide the "objectClass" property in your DirectorySearcher.Filter property member.
Will Marcouiller
Thanks Will Why is it that objectCatergory doesn't work, anyone know?
Stephen Murby
+2  A: 

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

You just need to spell it correctly: objectCategory - not objectCate*r*gory

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

marc_s
I knew i should have gone to school more often :P
Stephen Murby