Ternary operator in PowerShell – Stack Overflow
Posted by jpluimers on 2019/07/31
I like this built-in construct by fbehrens most:
$result = If ($condition) {"true"} Else {"false"}Everything else is incidental complexity and thus to be avoided.
For use in or as an expression, not just an assignment, wrap it in
$(), thus:
write-host $(If ($condition) {"true"} Else {"false"})
There are even more elegant constructs, but those require setting up an alias before using them.
Source: [WayBack] Ternary operator in PowerShell – Stack Overflow
–jeroen






Leave a comment