How do I select only the string that matched without the if statement running through every "paragraph"? Or how do I select a value from only one input object at a time?
Here is my thought process:
# Here I have treated each rule as a "paragraph" and used a delimiter on "next".
$content = Get-Content C:\firewallrules.txt -Delimiter 'next'
# For every "paragraph"
$content | ForEach-Object {
if($_ -Match 'set ips-sensor'){
"Value Found = " + $valuefound
# This prints every match I want to print ONLY the line that matched then iterate through the rest of the document
# Basically, I'm trying to say if($_ -Match 'set ips-sensor') then echo that specific line
$valuefound = $content | Select-String ips-sensor\s+.* | % { $_.Matches.Value }
}
else{
"Value Not Found"
}
}
My expected output would look something like this:
Value Not Found
Value Found = ips-sensor "default"
Value Found = ips-sensor "default"
Value Not Found
Value Not Found