Converting VBScript's CBool Function

Definition: Returns an expression that has been converted to a Variant of subtype Boolean.

CBool

Sure, you can convert a string or numeric value to a Boolean value (True or False): all you have to do is convert the data type of the variable to a Boolean type. As far as we know, 0 will always be converted to False and anything that isn't zero (even something as nonsensical as the string value cat) will be converted to True. In the following example we assign the value 0 to the variable $a, then convert $a to a Boolean value:

$a = 0
$a = [bool] $a

When you run this command and then echo back the value of $a you should get the following:

False

Return to the VBScript to Windows PowerShell home page