EDIT
My Regex was off, though, I'm having the same issue stull
https://regex101.com/r/wUHyZm/4
I was able to paste in a huge amount of input and got 50 matches using the link above, but still can't get powershell to flag a match.
Please see the below link for my regex and sample input
https://regex101.com/r/wUHyZm/4
https://regex101.com/r/wUHyZm/2
Basically I have a folder with a bunch of sub folders.
My script parses through each subfolder looking for "results.nmap".
It then opens the file (a text file) and I am intending for it to extract data that meets certain requirements.
Get-ChildItem -LiteralPath "U:\nmap reports\Nmap Subnet Scans\August2019" -Filter *.nmap -File -Recurse | foreach {
$currentfolder = $_.Directory
$RegX = [RegEx]'(?m)^Nmap scan report for\s+(?<Device>.+)\r?\n(?:.+\r?\n){3,6}23\/tcp\s+open\s+telnet$'
$content = Get-Content -Path "$currentfolder\results.nmap" -Raw
if ($content -match $RegX) {
Write-Host 'issa match'
}
#write-host $content
#[regex]::Matches($content,$RegX).ForEach({ $_.Groups['Device'].Value })
}
I can't seem to get it to match in powershell, but it matches in the link above.
I also don't get any errors
I had a previous question regarding the regex side, and a kind user provided:
[regex]::Matches($content,$RegX').ForEach({ $_.Groups['Device'].Value })
Which doesn't yield results either, though logically I don't see why it wouldn't.
Write-Host $content
Looks exactly like it should in my provided link above.
I'm not looking for an answer, moreso I'm looking for a good way to troubleshoot this so I can better teach myself