Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 819299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:17:07+00:00 2026-05-15T02:17:07+00:00

I have performed an LDAP:// query to get a list of computers within a

  • 0

I have performed an “LDAP://” query to get a list of computers within a specified OU, my issue is not being able to collect just the computer “name” or even “cn”.

        DirectoryEntry toShutdown = new DirectoryEntry("LDAP://" + comboBox1.Text.ToString());
        DirectorySearcher machineSearch = new DirectorySearcher(toShutdown);
        //machineSearch.Filter = "(objectCatergory=computer)";
        machineSearch.Filter = "(objectClass=computer)";
        machineSearch.SearchScope = SearchScope.Subtree;
        machineSearch.PropertiesToLoad.Add("name");
        SearchResultCollection allMachinesCollected = machineSearch.FindAll();
        Methods myMethods = new Methods();
        string pcName;
        foreach (SearchResult oneMachine in allMachinesCollected)
        {
            //pcName = oneMachine.Properties.PropertyNames.ToString();
            pcName = oneMachine.Properties["name"].ToString();
            MessageBox.Show(pcName);
        }

Help much appreciated.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:17:08+00:00Added an answer on May 15, 2026 at 2:17 am

    If you can upgrade to .NET 3.5, I would definitely recommend doing so.

    With .NET 3.5, you get a new System.DirectoryServices.AccountManagement namespace which makes a lot of these takes much easier.

    To find all computers and enumerate them, you’d do something like this:

    // define a domain context - use your NetBIOS domain name
    PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "YOURDOMAIN");
    
    // set up the principal searcher and give it a "prototype" of what you want to
    // search for (Query by Example) - here: a ComputerPrincipal
    PrincipalSearcher srch = new PrincipalSearcher();
    srch.QueryFilter = new ComputerPrincipal(ctx);;
    
    // do the search
    PrincipalSearchResult<Principal> results = srch.FindAll();
    
    // enumerate over results
    foreach(ComputerPrincipal cp in results)
    {
       string computerName = cp.Name;
    }
    

    Check out the Managing Directory Security Principals in the .NET Framework 3.5 on MSDN Magazine for more information on the new S.DS.AM namespace and what it offers.

    If you can’t move up to .NET 3.5 – you just need to keep in mind that the .Properties["name"] that you get from the search result is a collection of values – so in order to grab the actual pc name, use this:

    pcName = oneMachine.Properties["name"][0].ToString();
    

    You need to index the .Properties["name"] collection with a [0] to get the first entry (typically also the only entry – hardly any computer has more than one name).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to perform a SQL query to get the top 10 albums according
I have performed some initial research, but have not found exactly what I am
I am currently trying to perform an LDAP query in c++ to get the
Or does it just change where it's rendered? I have performed this transform and
I have performed all the diffrent tweeks I can find, but I still get
I have an operation that will be performed MANY times and so I need
I have to perform a query similar to: <?php //....connect to database $old =
i have performed like this Is there any thing wrong performed by me? NSURL
I have a standalone java project. I have performed a maven clean install. I
I have a list of dictionaries eg: [{'person':'guybrush','job':'pirate'},{'person':'leChuck','job':'pirate'}, {'person':'elaine','job':'governor'}] I want to display the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.