In my script i'm trying to test for true and false. Is this syntax incorrect?
$pdaout = ""
if ($pda.ActiveSyncEnabled.tostring() -like "True") {$pdaout = "TRUE"}
if ($pda.ActiveSyncEnabled.tostring() -like "False") {$pdaout = "-"}
write-host $pdaout
From stackoverflow
-
It should be, except may be for the
tostring()function (usetoString()to make sure there is no issue with the case sensitivity)Plus, you may want to use
elseifto avoid doing a second test if the first one was successful:if ($pda.ActiveSyncEnabled.toString() -like "True") {$pdaout = "TRUE"} elseif ($pda.ActiveSyncEnabled.toString() -like "False") {$pdaout = "-"} -
Seems like it would be better to just check the boolean value directly instead of using ToString():
$pdaout = "" if ($pda.ActiveSyncEnabled -eq $True) { $pdaout = "TRUE" } else { $pdaout = "-" } write-host $pdaoutHere is a blog post from the Windows Powershell team re: Boolean Values and Operators
0 comments:
Post a Comment