Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Collapse the table of content
Expand the table of content
Expand Minimize

Converting VBScript's CBool Function

Windows PowerShell

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


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:


Return to the VBScript to Windows PowerShell home page

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft