Author Posts

July 6, 2017 at 11:48 am

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
1) 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"}

July 6, 2017 at 1:06 pm

Ok, I have spotted the issue with the first bit. I had forgotten the grave ` character in front of the $ 🙂 I still have not come up with an elegant way of putting an -or between the 2 strings if 2 or more check boxes have been selected.