Saturday, September 11, 2010

Loading Computers from an AD OU into a C# List

This piece of code does as described: Loading Computers from an AD OU into a C# List. Often you want to put Computers into a List from a given OU, and have it recursively search through the depths of the tree. This code will let you search at the root to the various subordinate child OUs. This excerpt is from my S-Cubed Program. ("SCCM Sucks Shit!"). Screenshot above.

void loadLDAP(string OU)
                Base = new DirectoryEntry("LDAP://" + 

                DirectorySearcher mySearcher = new DirectorySearcher(Base);
                mySearcher.Filter = ("(objectClass=computer)");
                foreach (SearchResult resEnt in mySearcher.FindAll())
            catch (Exception ex)
                stsPWS.Text = "Can't contact Domain!";

No comments:

Post a Comment