Creating dynamic filter for where clause

Welcome Forums General PowerShell Q&A Creating dynamic filter for where clause

This topic contains 1 reply, has 1 voice, and was last updated by

1 year, 7 months ago.

  • Author
  • #74357

    Points: 64
    Rank: Member

    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

    Points: 64
    Rank: Member

    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.

The topic ‘Creating dynamic filter for where clause’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort