I have a report file that is generated and containes various file references. I am using Select-String and regular expressions to match on certain types of files and perform subsequent processing on them.
the dilemma I have is trying to consistently identify the number of matches when there are zero (0), one (1), or more than one (2+) matches. Here is what I've tried:
(select-string -path $outputfilePath -pattern $regex -allmatches).matches.count
This return "null" if there are 0 matches, "1" if one match, and "null" if more than one match.
(select-string -path $outputfilePath -pattern $regex -allmatches).count
this return "null" if there are 0 or 1 match and the number of matches if more than one match.
I'm faily new to Powershell, but am trying to find a consistent way to test on the number of matches regardless of whether there are 0, 1, or more than 1 match.