‘This script is hacked together, but works on my domains

‘ it connects to AD and extracts all the computer names and then writes them out to a file called servers.txt

Dim RootDSE, DomainNC, Connection, Command, RecordSet
‘ BEGIN CALLOUT A
Dim Stuff, myFSO, WriteStuff, dateStamp
dateStamp = Date()

Set RootDSE = GetObject(“LDAP://rootDSE”)
‘DomainNC = RootDSE.Get(“defaultNamingContext”)
DomainNC = RootDSE.Get(“configurationNamingContext”)
‘ END CALLOUT A
Set Connection = CreateObject(“ADODB.Connection”)
Connection.Open(“Provider=ADsDSOObject;”)
Set Command = CreateObject(“ADODB.Command”)
Command.ActiveConnection = Connection

‘ BEGIN CALLOUT B
Command.CommandText = “<LDAP://” & DomainNC _
& “>;(objectCategory=Computer);CN;subtree”
‘ END CALLOUT B
Command.Properties(“Cache Results”) = False
Command.Properties(“Page Size”) = 100
Command.Properties(“Sort On”) = “CN”
Command.Properties(“Timeout”) = 30
Set RecordSet = Command.Execute()

‘ BEGIN CALLOUT C

Set myFSO = CreateObject(“Scripting.FileSystemObject”)
Set WriteStuff = myFSO.OpenTextFile(“servers.txt”, 8, True)

Do While Not RecordSet.EOF
WriteStuff.WriteLine(RecordSet.Fields(“CN”).Value)
RecordSet.MoveNext()
Loop
‘ END CALLOUT C

WriteStuff.Close
SET WriteStuff = NOTHING
SET myFSO = NOTHING

Connection.Close()