I am aware of this question. It doesn't quite answer my question (or I'm failing to understand how to apply it).
I am attempting to search a selection of files in a directory for strings that may be ipv4 addresses. I am using the below code. I am fine with it over-matching things like version strings, and am prepared to manually ignore them.
gci -include *.vb,*.config, *.frm, *.dsr, *.cls, *.bas, *.iss, *.h, *.cs, *.resx, *.json, *.yml, *.xaml, *.wxs, *.wxi, *.wxl, *.cpp -recurse | % {
@'
File name - {0}
{1}
.....................
'@ -f $_.FullName, (get-content $_.FullName | select-string -pattern '^.*\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}.*$' )
} | out-file -filepath .\ips.txt
More often than not, the results are a System.Object[], rather than a string. I understand that this means multiple matches out of the Select-String.
How do I unfold these items while still working correctly with the single result lines?
Your task might be as easy as piping the output from
Get-ChildItemtoSelect-Stringdirectly then selecting the.Path(source) and.Lineproperties and lastly exporting to a Csv file:If you wanted to export to a plain text file you would first need to join all matched lines (the array of
.Lineoutputted bySelect-String) with a new line character to construct a single string, then you can interpolate that string: