Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Directory Entry c# get computer list

using System.DirectoryServices;  //add to references

public static List<string> GetComputers()
{
    List<string> ComputerNames = new List<string>();

    DirectoryEntry entry = new DirectoryEntry("LDAP://YourActiveDirectoryDomain.no");
    DirectorySearcher mySearcher = new DirectorySearcher(entry);
    mySearcher.Filter = ("(objectClass=computer)");
    mySearcher.SizeLimit = int.MaxValue;
    mySearcher.PageSize = int.MaxValue;

    foreach(SearchResult resEnt in mySearcher.FindAll())
    {
        //"CN=SGSVG007DC"
        string ComputerName = resEnt.GetDirectoryEntry().Name;
        if (ComputerName.StartsWith("CN="))
            ComputerName = ComputerName.Remove(0,"CN=".Length);
        ComputerNames.Add(ComputerName);
    }

    mySearcher.Dispose();
    entry.Dispose();

    return ComputerNames;
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: how to make a game 
Csharp :: vs code explorer font size 
Csharp :: check c# date for 0001/01/01 
Csharp :: unity system time 
Csharp :: winforms messagebox with button 
Csharp :: wpf rounded image 
Csharp :: C# multiple button click event to password textbox 
Csharp :: unity check if audio playing 
Csharp :: how to write switch statement unity 
Csharp :: how to set progress openedge driver name for odbc connection c# 
Csharp :: list of gender binary terrorists 
Csharp :: net.core "a path base can only be configured using iapplicationbuilder.usepathbase()" 
Csharp :: Codewars Multiply 
Csharp :: set decimal point c# 
Csharp :: avoid autocomplete input text asp.net 
Csharp :: c# loop 
Csharp :: fair division 
Csharp :: c# dynamic object get value 
Csharp :: how create another new app file in laravel 
Csharp :: convert dto to dictionary c# 
Csharp :: c# sort array string by length 
Csharp :: unity hub black screen 
Csharp :: how to make an object jump in unity 
Csharp :: csharp check if env is development 
Csharp :: regular expression for website url validation in c# 
Csharp :: c# postmessage mouse click 
Csharp :: rb.addforce c# 
Csharp :: unity waituntil coroutine 
Csharp :: generate random name c# 
Csharp :: entity framework update child records 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =