•      Powered by
 

Get a complete computer list from Active Directory using .NET 2.0.

by Steve Schofield.

This code sample shows how to retrieve an 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 to be a domain administrator level to retrieve this information.   

   Try
            Dim enTry As System.DirectoryServices.DirectoryEntry = New System.DirectoryServices.DirectoryEntry("LDAP://DC=Steve,DC=Schofield,DC=com")
            Dim mySearcher As System.DirectoryServices.DirectorySearcher = New System.DirectoryServices.DirectorySearcher(enTry)
            mySearcher.Filter = ("(objectClass=computer)")
            Dim resEnt As System.DirectoryServices.SearchResult
            For Each resEnt In mySearcher.FindAll()

                Try

                    Console.WriteLine(x & ":Processing:" & Mid(resEnt.GetDirectoryEntry().Name.ToString(), 4))

                Catch ex As Exception
                    Console.WriteLine("Trying to Connect to: " & resEnt.GetDirectoryEntry().Name.ToString() & vbCrLf & ex.Message.ToString())
                End Try
            Next

   Catch ex As Exception
            ErrorHandler("NOTHING", ex)
   End Try
 

tio

Terms of Use | Privacy Statement ©2005-2006 IISLogs.com. All rights reserved - Powered by IIS7 - info @ www.IIS.net