PowerShell Ternary Operator


As I know there is no ternary operator or even built-in expression to handle such thing in powerShell, but we still can do this following approach. 

# result = If ($condition) {"true"} Else {"false"}

$result = If (7 > 3) { "7 > 3" } Else { "7 < 3" }
$result

# or

Write-Host $(If (7 > 3) { "7 > 3" } Else { "7 < 3" })

source here.

Subscribe to receive free email updates:

0 Response to "PowerShell Ternary Operator"

Post a Comment