I have the following code to extract a string (strings) from multiple files in a folder and save the strings in a text file. I'd like to add the filename as the beginning of each line in the output.txt file so how do I get the filename for each file that I'm analyzing?
$input_path = ‘path’
$output_file = ‘output.txt’
$regex = '(.+?)'
select-string -Path $input_path -Pattern $regex -AllMatches | % { $_.Matches } | % { $_.Value } > $output_file