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:
Search line by line until "set name 'Web Traffic Filter - General"' is found then write line to file.
Once found keep looking though the file for the next line with 'set domain' is found then write line to file.
Once found keep looking though the file for the next line with 'set type' is found then write line to file.
Once found keep looking though the file for the next line with 'set action' is found then write line to file.
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 }}