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')