powershellboolean-expressionpowershell-7.0logical-orpowershell-7.2

Why does ($false || $true) evaluate to False in Powershell 7+?


In Powershell 7.2 Write-Output ($false || $true) will output False. Why?


Solution

  • Because it's not "logical OR", that would be -or or -bor. It is doing "if the first command failed, run the second one".

    Referencing the variable $false doesn't fail, so referencing the variable $true isn't executed.

    For comparison, try asdfg || $true, if the command is not found, you get an error and then $true.