Quantcast
Channel: Active questions tagged powershell-3.0 - Stack Overflow
Viewing all articles
Browse latest Browse all 129

trying to write a PowerShell script to look for certain strings in a text file

$
0
0

I am trying to write a PowerShell script to look for certain strings in a text file but not getting very far.,

What I want to do is:

  1. Search line by line until "set name 'Web Traffic Filter - General"' is found then write line to file.

  2. Once found keep looking though the file for the next line with 'set domain' is found then write line to file.

  3. Once found keep looking though the file for the next line with 'set type' is found then write line to file.

  4. Once found keep looking though the file for the next line with 'set action' is found then write line to file.

  5. Repeat though file.

Example taken from file

set name "Web Traffic Filter - General"config entriesedit 2set domain "*whois.com*"set type wildcardset action allownextedit 3set domain "*lufthansa.com*"set type wildcardset action allownextedit 4set domain "*partnerplusbenefit.com*"set type wildcardset action allownextedit 5set domain "www.lufthansa.com"set action allownext

This is what I have tried but not working:

foreach($line in Get-Content C:\Scripts\test.conf) {    # Find Policy Name    if($line -match 'set name "Web Traffic Filter - Restricted"'){        echo $line        echo ############################################################    }    # Find set domain    if($line -match 'set domain'){        echo $line    }    # Find set type    if($line -match 'set type'){        echo $line    }    # Find set action    if($line -match 'set action'){        echo $line    }}

Viewing all articles
Browse latest Browse all 129


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>