I am trying to build a dynamic filter for a where clause based on what checkboxes have been selected on a form
using the following code
If ($checkBox1.Checked -eq $True)
{write-host “Checkbox 1 selected”
$filterpr = “$.product -eq Windows 10 for 32-bit Systems"
}
If ($checkBox2.Checked -eq $True)
{write-host “Checkbox 2 selected”
$filterpr = "$.product -eq Windows Server 2016”
}
when I write-host instead of $filterpr being set to either $.product -eq Windows 10 for 32-bit System or $.product -eq Windows Server 2016 it is set to System.Windows.Forms.MouseEventArgs.product -eq Windows Serve
r 2016
So 2 questions
- how do I get the $_ into the variable and what would you suggest if the best way of adding a -or in the middle if both check boxes were selected i.e. the filter should be Where-object{$.product -eq “Windows 10 for 32-bit Systems” -or $.product -eq “Windows Server 2016” -and $_.Sev -eq “Critical”}