2

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

Ghawblin
  • 71
  • 2
  • 17

1 Answers1

0

In the ISE, you can use the debugger to step or set breakpoints, and run any arbitrary powershell command at the debug prompt, and mouse over variables to see their current value.

You can change the value of a variable and continue running. Even write a new function.

js2010
  • 23,033
  • 6
  • 64
  • 66
  • Yaknow, I just discovered the ISE. I've been using notepad++ to edit and just running my script every time to test.... – Ghawblin Aug 27 '19 at 18:52