How to perform short-circuit evaluation in Windows PowerShell 4.0?
I was looking for the same, came across this answer. The best so far in my opinion...
$cueNumber = 512
@{ $true = "This is true"; $false = "This is false" }[$cueNumber -gt 500]
Reference: https://adamtheautomator.com/a-simpler-ifthen-conditional-logic-in-powershell/
A simple set of test cases show that short-circuiting works:
PS C:\> 1 -eq 0 -or $(Write-Host 'foo')
foo
False
PS C:\> 1 -eq 1 -or $(Write-Host 'foo')
True
PS C:\> 1 -eq 1 -and $(Write-Host 'foo')
foo
False
PS C:\> 1 -eq 0 -and $(Write-Host 'foo')
False