Find string in .txt from a list of computers

Home Forums Scripting General Scripting Find string in .txt from a list of computers

  • This topic has 4 replies, 2 voices, and was last updated 13 years ago by AvatarLan.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    Lan
    Member
    #127631

    Hm lets see if I can explain this;

    from a text file on a local machine there is a list of computers.

    We want to run a check against this list and look for that machine on the network in a specific location (actually two locations) for a text file, then look in that file for a specific string, if this is there it adds the result into a log file.

    Any ideas?

    So far I have a folder on my c: drive set up called Barry (a bit different from test! lol).

    it’s only searching in the same location at the moment… but what I’d like is it to read a list of computernames from another text file to put that into the “Set objFile = objFSO.OpenTextFile(“\” & strcomputer & “c$Barrymap1.txt”, ForReading)” section and loop around all the various computers I specific in the text file…

    Also I need to work out how to output the results into a text file… so it reports out if its there or not;

    Computername – yes
    computername – no
    computername – yes

    etc.

    Code:
    Const ForReading = 1

    Set objRegEx = CreateObject(“VBScript.RegExp”)
    objRegEx.Pattern = “…FINDME…”

    Set objFSO = CreateObject(“Scripting.FileSystemObject”)
    Set objFile = objFSO.OpenTextFile(“C:Barrymap1.txt”, ForReading)

    Do Until objFile.AtEndOfStream
    strSearchString = objFile.ReadLine
    Set colMatches = objRegEx.Execute(strSearchString)
    If colMatches.Count > 0 Then
    For Each strMatch in colMatches
    Wscript.Echo strSearchString
    Next
    End If
    Loop

    objFile.Close

    Wscript.Echo “done 1, working on 2”

    Set objFSO = CreateObject(“Scripting.FileSystemObject”)
    Set objFile = objFSO.OpenTextFile(“C:Barrymap2.txt”, ForReading)

    Do Until objFile.AtEndOfStream
    strSearchString = objFile.ReadLine
    Set colMatches = objRegEx.Execute(strSearchString)
    If colMatches.Count > 0 Then
    For Each strMatch in colMatches
    Wscript.Echo strSearchString
    Next
    End If
    Loop

    objFile.Close

    Wscript.Echo “done 2. End”

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.