Advertisement

09.09.2008 at 06:12AM PDT, ID: 23715270
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

Get computers and domains in Active Directory

Asked by ChrisMDrew in .NET Framework 2.x, C# Programming Language, Active Directory

Tags:

I want to recover a complete list of computers and the domains that they are in from Active Directory using the functionailty built in to .NET 2.0.  I have determined how to get ALL computers in the default domain using the following code:

// Identify the 'default' AD/LDAP Server
DirectoryEntry defaultServer = new DirectoryEntry("LDAP://rootDSE");
string strLdapServer = (string)defaultServer.Properties["defaultNamingContext"].Value;
DirectoryEntry mySearchRoot = new DirectoryEntry("LDAP://" + strLdapServer);

// Create a 'DirectoryEntry' object to search.            
DirectorySearcher myDirectorySearcher = new DirectorySearcher(mySearchRoot);
myDirectorySearcher.Filter = ("(objectClass=computer)");

// Iterate through (any) results
foreach(SearchResult resEnt in myDirectorySearcher.FindAll())
{
    // Get the 'DirectoryEntry' that corresponds to 'mySearchResult'.
   DirectoryEntry myDirectoryEntry = resEnt.GetDirectoryEntry();
   string strComputer = myDirectoryEntry.Name.ToString();
}

...and I have also determined code to recover a list of domains defined within AD as :

List<string> domains = new List<string>()
DirectoryEntry en = new DirectoryEntry("LDAP://");

// Search for objectCategory type "Domain"
DirectorySearcher srch = new DirectorySearcher("objectCategory=Domain");
SearchResultCollection coll = srch.FindAll();

// Enumerate over each returned domain.
foreach (SearchResult rs in coll)
{
      ResultPropertyCollection resultPropColl = rs.Properties;
      foreach (object domainName in resultPropColl["name"])
      {
            domains.Add(domainName.ToString());
      }
}


...now what I want to do is to use the name of the domain returned as above to recover the name of any computers within this domain.  I did try using the following code:

string ldapString = "LDAP://" + domainName + "/CN=Computers,DC=" + domainName + ",DC=com";
DirectoryEntry domain = new DirectoryEntry(ldapString);
foreach (DirectoryEntry child in domain.Children)
{
    string computerName = child.Name;
    if (computerName != "")
      computers.Add(new string[] { computerName, domainName });
}

But this fails to connect to the AD server.  Ultimately I need some code which, given the domain name, is able to query the AD server for that domain and recover the list of computers on that domain but I seem to be having problems determining the correct LDAP string.Start Free Trial
[+][-]09.11.2008 at 02:57PM PDT, ID: 22455444

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 14-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]09.12.2008 at 04:59AM PDT, ID: 22458816

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.12.2008 at 05:11AM PDT, ID: 22458889

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.12.2008 at 05:17AM PDT, ID: 22458934

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.12.2008 at 07:32AM PDT, ID: 22460195

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.12.2008 at 08:19AM PDT, ID: 22460678

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.12.2008 at 08:22AM PDT, ID: 22460697

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.15.2008 at 02:05AM PDT, ID: 22476744

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.15.2008 at 03:09AM PDT, ID: 22477064

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: .NET Framework 2.x, C# Programming Language, Active Directory
Tags: C# .NET
Sign Up Now!
Solution Provided By: Chris-Dent
Participating Experts: 1
Solution Grade: A
 
 
[+][-]09.15.2008 at 07:56AM PDT, ID: 22479211

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-43 / EE_QW_2_20070628