The –and
and –or
comparison operators are used to evaluate multiple expressions present within a single line of code. These are used to see whether two or more expressions evaluate to be True
. The –and
comparison operator mandates that both evaluations must evaluate to be True
to proceed in the statement. This means that expression1
and expression2
must be True
to continue. The –or
comparison operator only requires one of the two expressions to be True
. This means that expression1
or expression2
can be True
to continue. As you are learning PowerShell, you will want to use caution while using the -and
and -or
comparison operators as they can quickly complicate the logic of your scripts.
A script that shows how to use –and
and -or
comparison operators would look like this:
$myvar = $True $myothervar = $False If ($myvar –eq $True –AND $myothervar –eq $False) { Write-Host "Both statements evaluate to be True" } If ($myvar –eq $True –OR $myothervar –eq $True) { Write...