I am trying to search a text file for a specific string and output the line and its context:
$StateCheck = Select-String -Path C:\ImageManagerTool\Results.txt -Pattern "State:*"
$SValueCheck = Select-String -Path C:\ImageManagerTool\Results.txt -Pattern "State Value:*"
If(Get-Content C:\ImageManagerTool\Results.txt | %{$StateCheck -notmatch "State: Active"})
{
Get-Content C:\ImageManagerTool\Results.txt | Select-String -Pattern "State:*"-Context 2,7| Select-String -Pattern "State: Active" -NotMatch |Select-String -Pattern "State Value:*" -NotMatch
}
If(Get-Content C:\ImageManagerTool\Results.txt | %{$SValueCheck -notmatch "State Value: 0"})
{
Get-Content C:\ImageManagerTool\Results.txt | Select-String -Pattern "State Value:*"-Context 3,6| Select-String -Pattern "State Value: 0" -NotMatch
}
Results of Above Script:
So far, all that I've been able to accomplish is outputting the string instances I want to find, but not their context. With the current setup of 'if' statements to filter the data for strings that don't match, I haven't figured out if using the parameter -context will work in this situation, since -context isn't valid on receiving Select-String commands. When reading Microsoft's description of -Context on the PowerShell site, it states that context is stored as an array of strings in the context property of an object. Is there a way I can either rewrite my script pieces to get the desired effect(i.e. a switch?) or utilize the context parameter as a property to output its data?

C:\ImageManagerTool\Results.txtseveral times, store it in a variable and act on it. Also show the content by editing your question.