On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Const ForReading = 1
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("4.txt", ForReading)
i = 0
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
objDictionary.Add i, strNextLine
i = i + 1
Loop
For Each objItem in objDictionary
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = _
"SELECT Name FROM " & objDictionary.Item(objItem) & " WHERE objectCategory='computer'"
Set objRecordSet = objCommand.Execute
While Not objRecordset.EOF
Wscript.Echo objRecordSet.Fields("Name").Value
objRecordSet.MoveNext
Wend
objConnection.Close
NextI need to get a list cf computers present in different OUs. I have the OUs in a text file. Can anyone tell me what is wrong with above script. It is stuck without giving any errors. I have modified it from below script which is working fine.
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = _
"SELECT Name FROM 'LDAP://OU=Laptops,OU=computers,OU=Velachery,OU=TCS - Chennai,OU=TCS - India,DC=India,DC=TCS,DC=com' WHERE " & _"objectCategory='computer'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo objRecordSet.Fields("Name").Value
objRecordSet.MoveNext
Loop