How to: Get a list of the names of all the computers on a domain

How to: Get a list of all computers on the domain

add the following references:

System.DirectoryServices
System.Net
System.Net.NetworkInformation

The following method will return a string list of all the computer names on the domain:

private List<string> GetListOfAllDomainComputers()
{
List<string> domainComputers = new List<string>(30);
try
{
IPGlobalProperties ipgProperties = IPGlobalProperties.GetIPGlobalProperties();
string domain = ipgProperties.DomainName;
DirectoryEntry domainEntry = new DirectoryEntry(“WinNT://” + domain);
domainEntry.Children.SchemaFilter.Add(“computer”);
foreach (DirectoryEntry computer in domainEntry.Children)
domainComputers.Add(computer.Name);
}
catch (Exception x)
{
HandleException(x);
}
return domainComputers;
}

solution found here: source

MGR: the Intelogist

About MGR: the Intelogist

SharePoint Server developer, turned Sitefinity developer, turned Angular developer, turned SharePoint Online consultant, turned Unily consultant, turned O365 consultant... Never a dull moment!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

This site uses Akismet to reduce spam. Learn how your comment data is processed.