Get a Complete Computer List From Active Directory Using .NET 2.0
This code sample shows how to retrieve a list of computers from Active Directory
and use a For/Next to loop through the collection. I've used this code sample
on several scripts and using Active Directory as the authoritative source for a
list of machines is handy. The process running this code sample normally requires
domain administrator level to retrieve this information.
Note: The "LDAP://DC=Steve,DC=Schofield,DC=com" is the LDAP path for the domain
I'm connecting to. This represents an LDAP-based path to the Active Directory domain
you are connecting to. You will want to change the code sample to what domain you
are connecting to.
Dim enTry As System.DirectoryServices.DirectoryEntry
Dim mySearcher As
System.DirectoryServices.DirectorySearcher = _
mySearcher.Filter = ("(objectClass=computer)")
Dim resEnt As
For Each resEnt In mySearcher.FindAll()
'The reason for using the MID statement is when retrieving
'With this method, they are formatted CN=COMPUTERNAME.
The MID statement
'Parses out just the ComputerName. 'CN' stands for
'common name', this is
'The way LDAP stores the computer variable.
Console.WriteLine(":Processing:" & _
ex As Exception
Console.WriteLine("Trying to Connect to: " & _
vbCrLf & ex.Message.ToString())
Steve Schofield is a Senior Internet Support
ORCS Web, Inc.
- a company that provides managed complex hosting for clients who develop and deploy their applications on Microsoft Windows platforms.
Steve Schofield is a Senior Internet Support Specialist with ORCS Web, Inc. - a company that provides managed complex hosting for clients who develop and deploy their applications on Microsoft Windows platforms.