VB Script to get list of Network Computers

Vb Script to get list of Network Computers.

Create Table ListOfServers
(
	ServerName Varchar(20),
	DomainName Varchar(50),
	CreatedDate DateTime
)

 

'On error resume next
Const DB_CONNECT_STRING = "Provider=SQLOLEDB.1;Data Source=ExtreamAdvice;Initial Catalog=Nirav's Diary;user id ='sa';password='password'"
Set myConn = CreateObject("ADODB.Connection")
Set myCommand = CreateObject("ADODB.Command" )
myConn.Open DB_CONNECT_STRING
Set myCommand.ActiveConnection = myConn

Const ADS_SCOPE_SUBTREE = 2
strDomainDn = "DomainName"

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
    "Select Name, Location from 'LDAP://" & strDomainDn & "' " _
        & "Where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF
    strComputer = objRecordSet.Fields("Name").Value
    myCommand.CommandText = "Insert into ListOfServers (ServerName, DomainName,CreatedDate) values('" & strComputer & "','" & strDomainDn & "',getdate())"
    myCommand.Execute
    objRecordSet.MoveNext
Loop
myConn.Close

WScript.Echo "Done!"

Regards,
Nirav Gajjar