Search notes:

PowerShell: logical operators

The logical operators in PowerShell are: -and, -or, -xor, -not and !.
The exclamation mark is equivalent to -not.
A logical operator evaluates to a boolean data type.

Short-circuiting

The logical operators perform short-circuit evaluation, that is, only parts of an expression with logical operators are evaluated that are needed to determine the result.
For example, if the left argument to -or is $true, the right argument does not need to be looked at because the entire expression is $true anyway.
In the following example, the write-host cmdlet is not invoked:
PS C:\> $true -or (write-host 'Evaluated')
However, here it is:
PS C:\> $false -or (write-host 'Evaluated')

See also

The if statement
operators

Index