I have a script that captures and displays the line of a string match. Very simple. What I need now is the previous line to be displayed. I may need the previous few lines but for now my task is to just capture and display the previous line once a string match is found.
Here is my current script. I have no clue how to alter it for my purposes. Any help is appreciated.
$searchWords="NEW", "CATLG", "DELETE"
# List the starting (parent) directory here - the script will search through every file and every sub-directory - starting from the one listed below
Get-Childitem -Path "C:\src\" -Include "*.job" -Recurse |
Select-String -Pattern $searchWords |
# the output will contain the [Found] word, the document it found it in and the line contents/line number containing the word
Select Filename,Line,@{n='SearchWord';e={$_.Pattern}}, LineNumber