Good evening. Stack Overflow and Powershell and RegEx novice here.
The below Powershell code is returning some but not enough parts of the string to make a visual verification. It might be returning the wrong fields.
For example, it is capturing variables in a JSON file for a variable called "CallingApplication". However I need more parts of the string.
Expected results: When I select Item1 checkbox, the below text should appear underneath the check icon and Item 1 text box. (the example CSV file shows enough characters and the results I want)

Actual Results: When I select Item1 checkbox, the below texts appears, which is incorrect or lacking

Below is the code I have so far. Any help would be appreciated. Please keep answers simple and with examples as I am a newbie. Thank you!
set-location C:\Users\B187515\Downloads\
$file = Get-ChildItem -Path C:\Users\B187515\Downloads\ -filter
*.json | Sort-Object LastAccessTime -Descending | Select-Object -
First 1
#Build the GUI
[xml]$xaml = @"
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="Window" Title="Initial Window" WindowStartupLocation =
"CenterScreen"
SizeToContent = "WidthAndHeight" ShowInTaskbar = "True" Background =
"lightgray">
<StackPanel >
<CheckBox x:Name="Item2" Content = 'AgencyGroup DNE' />
<CheckBox x:Name="Item1" Content = 'CallingApplication' />
<CheckBox x:Name="Item16" Content = 'PPVCount' />
<TextBox x:Name='Item1_txt' />
<TextBox x:Name='Item2_txt' />
</StackPanel>
</Window>
"@
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
#Connect to Controls
$Window=[Windows.Markup.XamlReader]::Load( $reader )
# define 1 textbox beneath the variables only
$Item1_txt = $Window.FindName('Item1_txt')
$Item2_txt = $Window.FindName('Item2_txt')
$Item1 = $Window.FindName('Item1')
$Item2 = $Window.FindName('Item2')
$Item16 = $Window.FindName('Item16')
#Events
## Item1
$Item1.Add_Checked({
If ($Item1.IsChecked) { $CA = “CallingApplication"
Get-Content $file | Select-String -Pattern $CA -Context 2| ForEach-
Object {
$_.LineNumber
$_.Line
$_.Pattern
$_.Context.PreContext
$_.Context.PostContext
$Item1_txt.Text = $_.LineNumber, $_.Line, $_.Context.PostContext
}
}
else {$CA ="!$!"}
})
$Item1.Add_UnChecked({
$Item1_txt.Text = ""
})
$Item2.Add_Checked({
If ($Item2.IsChecked) { $AG = “'AgencyGroup"
Get-Content $file | Select-String -Pattern $AG -Context 2| ForEach-
Object {
$_.LineNumber
$_.Line
$_.Pattern
$_.Context.PreContext
$_.Context.PostContext
$Item1_txt.Text = $_.LineNumber, $_.Line, $_.Context.PostContext
}
}
else {$AG ="!$!"}
})
$Item2.Add_UnChecked({
$Item1_txt.Text = ""
})
$Item16.Add_Checked({
If ($Item16.IsChecked) { $PPVCount = “PPVCount"
Get-Content $file | Select-String -Pattern $PPVCount -Context 1|
ForEach-Object {
$_.LineNumber
$_.Line
$_.Pattern
$_.Context.PreContext
$_.Context.PostContext
$Item1_txt.Text = $_.LineNumber,
$_.Line, $_.Context.PreContext, $_.Context.PostContext
}
}
else {$PPVCount ="!$!"}
})
$Item16.Add_UnChecked({
$Item1_txt.Text = ""
$Item2_txt.Text = ""
})
$Window.Showdialog() | Out-Null
PPVCount in the program only shows lines 1332/1333

PPVCount actually appears on lines 859/860 and 1332/1333 in JSON file. I'd like both lines to appear when I select the checkbox
