I am trying to create a GUI in Powershell Studio to search EventLogs and wanted to be able to use multiple “terms” and IDs to search on. I started off basic with 2 textboxes (EventIDs and SearchTerms), a datagridview to display the results and a submit button.
Ignoring the textboxes and just populating the Datagridview works just fine with the below using 2 terms and 2 IDs:
<pre>$SearchTerms = "C:\windows\system32\wininit.exe", "C:\windows\system32\autochk.exe", "guest"
$EventIDs = 4797,4688
$Logname = "Security"
$LogResuts = get-winevent -erroraction Stop -FilterHashtable @{ logname = $Logname; ID = $EventIDs; data = $SearchTerms }
Update-DataGridView -DataGridView $datagridview1 -item $LogResuts</pre>
I started with just one textbox filling in the "$EventIDs variable and changed the above to:
<pre>$SearchTerms = "C:\windows\system32\wininit.exe", "C:\windows\system32\autochk.exe", "guest"
$EventIDs = $textboxEventIDs.text
$Logname = "Security"
$LogResuts = get-winevent -erroraction Stop -FilterHashtable @{ logname = $Logname; ID = $EventIDs; data = $SearchTerms }
Update-DataGridView -DataGridView $datagridview1 -item $LogResuts</pre>
Putting 1 ID in the box works fine but am unsure how to do 2 and separate them.
Filling in this works: 4797
Filling in this DOES NOT work: 4797,4688
How can I accomplish this?
I would like to be able to do that same with the "SearchTerms too if possible.
Again if I fill in one value it works fine: C:\windows\system32\wininit.exe
This does not work and crashes the form like above: C:\windows\system32\wininit.exe , C:\windows\system32\autochk.exe
I know the issue is just the way I am formatting the text or presenting it from the textbox(s) but am too new to know why or how to fix it :)
Thanks for any help you can give.