I\'m trying to convert an argument of my PowerShell script to a boolean value. This line
[System.Convert]::ToBoolean($a)
works fine as long
Another possibility is to use the switch statemement and only evaluate True, 1 and default:
$a = "Bla"
$ret = switch ($a) { {$_ -eq 1 -or $_ -eq "True"}{$True} default{$false}}
In this if the string equals to True $true is returned. In all other cases $false is returned.
And another way to do it is this:
@{$true="True";$false="False"}[$a -eq "True" -or $a -eq 1]
Source Ternary operator in PowerShell by Jon Friesen