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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search Multiple Files on Multiple Computers

Status
Not open for further replies.

Rambeaux007

IS-IT--Management
May 4, 2005
23
US
I am trying to work out a script that will read multiple log files on multiple computers. I just can't seem to figure out how to get this accomplished. Here is the code I have so far....

strComputers = objFile.ReadAll
objFile.Close
arrComputers = Split(strComputers, vbCrLf)

For Each strComputer In arrComputers

Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Global = True
objRegEx.Pattern = "[0-9]{1,3}.[0-9]{1,3}"

Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FileExists("\\" & strComputer & "\c$\Test.log") Then
Set objFile = objFSO.OpenTextFile("\\" & strComputer & "\Test.log", ForReading)


strSearchString = objFile.ReadAll
objFile.Close

Set colMatches = objRegEx.Execute(strSearchString)

If colMatches.Count > 0 Then

For Each strMatch in colMatches
strMatch2 = strMatch.value
Next
End If

'*************************************************************************************
Call Show(strComputer, strMatch2)
'*************************************************************************************


End If




 
Well, for starters you have not defined objFile to build your array from.

I'd move the Set objFSO to above the For Next so you are not recreating the object each time.

The end of your script seems to be missing a lot. Where is your Show function that you are calling?

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
[1] You have a line break after "then", you need end if.
[2] missing \c$.
[tt]
If objFSO.FileExists("\\" & strComputer & "\c$\Test.log") Then
Set objFile = objFSO.OpenTextFile("\\" & strComputer & "[red]\c$[/red]\Test.log", ForReading)
[blue]end if[/blue]
[/tt]
[3] For a remote file, you have less idea how it's, hence, better put a bit of control.
[tt]
if objFile.size<>0 then
strSearchString = objFile.ReadAll
else
strSearchString = ""
end if
[/tt]
 
Actuallay I didn't want to put all the code here. But here is the entire Script. It opens an excel spreadsheet then outputs the information gathered from the log file on each computer. I need it to read more than just the one log file on a computer. Thanks for your help!!





Dim pFolderName : pFolderName = "computers.txt"
Dim intIndex
Dim strMatch2
Dim objpath
Dim strComputer
Dim AbsoluteRelative

Const ForReading = 1

'*********************************************************************************
INPUT_FILE_NAME = Inputbox("Type in the location of the Serverlist file. It must be named computers.txt. ie. c:\computers.txt", "Serverlist")
Const FOR_READING = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(INPUT_FILE_NAME, FOR_READING)

'**********************************************************************************
Dim oXLS : Set oXLS = WScript.CreateObject("Excel.Application")

''Open and configure Excel
oXLS.Visible = TRUE
oXLS.WorkBooks.Add
oXLS.Columns(1).ColumnWidth = 20
oXLS.Columns(2).ColumnWidth = 20
oXLS.Columns(3).ColumnWidth = 30

''Set column headers
oXLS.Cells(1, 1).Value = "Computer Name"
oXLS.Cells(1, 2).Value = "Score"
oXLS.Cells(1, 3).Value = "Message"

''Format text (bold)
oXLS.Range("A1:C1").Select
oXLS.Selection.Font.Bold = True
oXLS.Selection.Interior.ColorIndex = 1
oXLS.Selection.Interior.Pattern = 1 ''xlSolid
oXLS.Selection.Font.ColorIndex = 2

''Left Align text
oXLS.Columns("B:B").Select
oXLS.Selection.HorizontalAlignment = &hFFFFEFDD '' xlLeft

intIndex = 3

'*********************************************************************************
'Read Textfile and output results

strComputers = objFile.ReadAll
objFile.Close
arrComputers = Split(strComputers, vbCrLf)

For Each strComputer In arrComputers

Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Global = True
objRegEx.Pattern = "[0-9]{1,3}.[0-9]{1,3}"

Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FileExists("\\" & strComputer & "\c$\Test.log") Then
Set objFile = objFSO.OpenTextFile("\\" & strComputer & "\c$\Test.log", ForReading)


strSearchString = objFile.ReadAll
objFile.Close

Set colMatches = objRegEx.Execute(strSearchString)

If colMatches.Count > 0 Then

For Each strMatch in colMatches

strMatch2 = strMatch.value
strMatch3 = "Message"
Next
End If
'*************************************************************************************
Call Show(strComputer, strMatch2)
'*************************************************************************************

Set colMatches = objRegEx.Execute(strSearchString)

If colMatches.Count > 0 Then

For Each strMatch in colMatches

strMatch2 = strMatch.value
strMatch3 = "Message"
Next
End If
'*************************************************************************************
Call Show(strComputer, strMatch2)
'*************************************************************************************

Else
strMatch2 = "N/A"
AbsoluteRelative = "N/A"
Call Show(strComputer, strMatch2)
End If

Next

'**************************************************************************************

Sub Show(strComputer, strMatch2)


oXLS.Cells(intIndex, 1).Value = strComputer
oXLS.Cells(intIndex, 2).Value = strMatch2
oXLS.Cells(intIndex, 3).Value = strMatch3
intIndex = intIndex + 1
oXLS.Cells(intIndex, 1).Select

End Sub


'***************************************************************************************

Msgbox ("Script has finished!")

 
>Actuallay I didn't want to put all the code here.
That's is right thing to do, we do not want to read the entire script as well unless necessary. But, what about correcting those mistakes mentioned and what happens? Those are material. Whether you read or write anything form any source text file or excel are just anedotal.
 
I have made the corrections. The script works....as is. My issue is modifying it so that it will read multiple files of the same file type within a given folder on multiple computers. As you can see it already loops throught multiple computers. I just don't know where to start for reading multiple files.
 
use the FileSystemObject Files method.

Code:
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oDir = oFSO.GEtFolder("C:\")
For Each oFile in oDir.Files
   Wscript.Echo oFile.Name
Next

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top