Logical operators
Logical operators evaluate two or more comparisons or other operations that produce a Boolean
(true or false) result.
The following logic operators are available:
- And:
-and
- Or:
-or
- Exclusive or:
-xor
- Not:
-not
and!
and
The -and
operator returns true if the values on the left-hand and right-hand sides are both true.
For example, each of the following returns $true
:
$true -and $true
1 -lt 2 -and "string" -like 's*'
1 -eq 1 -and 2 -eq 2 -and 3 -eq 3
(Test-Path C:\Windows) -and (Test-Path 'C:\Program Files')
The -and
operator is often combined with the -or
operator.
or
The -or
operator returns true if the value on the left, the value on the right, or both are true
.
For example, each of the following returns $true
:
$true -or $true
2 -gt 1 -or "something" -ne "nothing"
1 -eq 1 -or 2 -eq 1
(Test-Path C:\Windows) -or (Test-Path D:\Windows)
The...