0

I'm trying to so write a PowerShell script that performs a task based on the input from a windows form.

If ($ComboBoxOffice.Text -eq 'Norwich', $CheckBoxNoEquipment.Checked -eq 'False' ) 

I can get it to work with just the following code:

If ($ComboBoxOffice.Text -eq 'Norwich')

Any ideas on how would go about only actioning the IF statement based on the input from the first code?

  • 4
    Are you looking for `-and` condition? See if [this](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_logical_operators?view=powershell-7.1) helps. – shahkalpesh May 21 '21 at 14:26

1 Answers1

0

Assuming you only want to proceed when BOTH conditions are satisfied, use the -and operator:

if($ComboBoxOffice.Text -eq 'Norwich' -and $CheckBoxNoEquipment.Checked -eq $false){
    # ...
}

If you want to proceed when either condition is satisfied, use -or:

if($ComboBoxOffice.Text -eq 'Norwich' -or $CheckBoxNoEquipment.Checked -eq $false){
    # ...
}

Notice that I'm using the special boolean variable $false rather than the string 'False', to avoid type confusion bugs

Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206