Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

strSearchFor - feed info from text file...?

Status
Not open for further replies.

insanity1

Technical User
Nov 30, 2004
40
CA
Is there any way to take the script below and feed information to 'strSearchFor' from a text file?

to search for, in order:
bla
bla1
bla2


Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

strSearchFor = "BLA"

objCommand.CommandText = _
"Select Name, Location from 'LDAP://ou=subouname,ou=ouname,dc=owfg,dc=com' " _
& "Where objectCategory='computer'"
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
''''''''''''''''''''''''''
'Create and open dest file
''''''''''''''''''''''''''
strWriteFile = WSHShell.CurrentDirectory & "\" & strSearchFor & ".txt"
Set CreateFile = oFSO.CreateTextFile(strWriteFile, True)
CreateFile.Close
Set strWriteFile = oFSO.OpenTextFile(strWriteFile, ForWriting)
'''''''''''''''
'Write to file
'''''''''''''''
Do Until objRecordSet.EOF
strComputerName = objRecordSet.Fields("Name").Value
If inStr(1, strComputerName, strSearchFor, vbTextCompare) Then strWriteFile.WriteLine _
(strComputerName)
objRecordSet.MoveNext
Loop
 


How about:
Code:
....

objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

[blue]Open "C:\TextFile.txt" For Input As #1
Do While Not EOF(1)   [green]' Loop until end of file.[/green]
   Line Input #1, strSearchFor   [green]' Read line into variable.[/green]
[/blue]

    objCommand.CommandText = _
        "Select Name, Location 

.......

    If inStr(1, strComputerName, strSearchFor, vbTextCompare) Then 
        strWriteFile.WriteLine (strComputerName)
        objRecordSet.MoveNext
    Loop
[blue]Loop[/blue]

Have fun.

---- Andy
 
Thanks for the info!

I am now getting the following error with the changes...just wondering if you have an idea as to what the issue could be... have been unable to determine so far.
_______________________________________________
Script: scriptname
Line: 16
Char: 24
Error: Expected end of statement
Code: 800A0401
Source: Microsoft VBScript compilation error
_______________________________________________
This is what I have:

Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

Open "c:\TextFile.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, strSearchFor

objCommand.CommandText = _
"Select Name, Location from 'LDAP://ou=subouname,ou=ouname,dc=domain,dc=com' " _
& "Where objectCategory='computer'"
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
''''''''''''''''''''''''''
'Create and open dest file
''''''''''''''''''''''''''
strWriteFile = WSHShell.CurrentDirectory & "\" & strSearchFor & ".txt"
Set CreateFile = oFSO.CreateTextFile(strWriteFile, True)
CreateFile.Close
Set strWriteFile = oFSO.OpenTextFile(strWriteFile, ForWriting)
'''''''''''''''
'Write to file
'''''''''''''''
Do Until objRecordSet.EOF
strComputerName = objRecordSet.Fields("Name").Value
If inStr(1, strComputerName, strSearchFor, vbTextCompare) Then strWriteFile.WriteLine _
(strComputerName)
objRecordSet.MoveNext
Loop
Loop


Thanks again for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top