Search code examples
c#.net-3.5active-directorydirectoryservices

C#.NET: Retrieve list of computers in a FOLDER in a domain


How do I Retrieve a list of computers in a FOLDER in a domain. lets say i have maydomain.dom as my domain and I have a folder containing some computers.


Solution

  • Following code to list out computers in your domain and in active directory, this may help you

    //ActiveDirectorySearch1
    //Displays all computer names in an Active Directory
    using System;
    using System.DirectoryServices; 
    namespace ActiveDirectorySearch1
    {
    class Class1
    {
    static void Main (string[] args)
    {
    //Note : microsoft is the name of my domain for testing purposes.
    DirectoryEntry entry = new DirectoryEntry(LDAP://microsoft);
    DirectorySearcher mySearcher = new DirectorySearcher(entry);
    mySearcher.Filter = ("(objectClass=computer)");
    Console.WriteLine("Listing of computers in the Active Directory"); 
    Console.WriteLine("============================================"); foreach(SearchResult resEnt in mySearcher.FindAll())
    { 
    Console.WriteLine(resEnt.GetDirectoryEntry().Name.ToString()); }
    Console.WriteLine("=========== End of Listing ============="); 
    }
    }
    }
    

    http://www.c-sharpcorner.com/UploadFile/jodonnell/ListAllComps07022005005654AM/ListAllComps.aspx