I have a question towards ternary operators in Powershell 5.1. It doesn't work as I expected it if I try to assign an array @(...):
# I can assign an array to a variable:
$a=@("TRUE")
write-host "a:" $a
# I can do that in a proper if/then statement, too:
$b = @(if ($false) {@("True")} else {@("False")})
write-host "b:" $b
# Assignment of string constants works fine with ternary syntax:
$c = @( {"True"} , {"False"} )[!$true]
write-host "c:" $c
# but not with array assignments:
$d = @( {@("True")} , {@("False")} )[!$false]
write-host "d:" $d
# Expected: "False".
# Actual output: @("False")
Output:
a: TRUE
b: False
c: "True"
d: @("False")
A thread regarding ternary operators doesn't clarify this for me. (Ternary operator in PowerShell)
Update: $d needs to be an array, as well as the two inner items. Here they were shown with just one string constant for simplicity.