I need to search 10-15 strings into the entire application codes(more than 10000 programs) so I have inserted the strings that i need to search in a text file "strings.text". I also need to know the previous and next line of the matched string line so I am using "Context 1" in the below script. However, the below script is giving output as only Matched String line.
$content = Get-Content strings.txt
ForEach ($Word in $content){
Get-ChildItem -recurse | Select-String -pattern $Word -Context 1 | Select-Object path,line,linenumber,filename | Export-csv -Path "\result_$word.csv"
}
Output:
Path Line LineNumber FileName
desktop\prog1.txt Server(xyz) 3 prog1.txt
desktop\prog2.txt Server(xyz) 6 prog2.txt
What I really want is
Path Line LineNumber FileName
Connect 2 prog1.txt
desktop\prog1.txt Server(xyz) 3 prog1.txt
stop 4 prog1.txt
Connect 8 prog2.txt
desktop\prog2.txt Server(xyz) 9 prog2.txt
stop 10 prog2.txt
Can anyone please help how can I get this output?