Creating dynamic filter for where clause

This topic contains 1 reply, has 1 voice, and was last updated by Profile photo of Simon B Simon B 3 weeks, 1 day ago.

  • Author
    Posts
  • #74357
    Profile photo of Simon B
    Simon B
    Participant

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

  • #74366
    Profile photo of Simon B
    Simon B
    Participant

    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.

You must be logged in to reply to this topic.