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 entries
edit 2
set domain "*whois.com*"
set type wildcard
set action allow
next
edit 3
set domain "*lufthansa.com*"
set type wildcard
set action allow
next
edit 4
set domain "*partnerplusbenefit.com*"
set type wildcard
set action allow
next
edit 5
set domain "www.lufthansa.com"
set action allow
next
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
}
}