When I study PowerShell scripting language, I knew the data type is auto-assignment. If I want to declare a Boolean type variable, how can I do it?
Example: $myvariable = "string" or $myvalue = 3.14159 $myboolean ?
Boolean values (which can be either 1 or 0) are defined in PowerShell using the .Net System.Boolean type (the short from of which is [bool]). For example, the following command assigns true to a variable of boolean type:
PS C:\Users\Administrator> [bool] $myval = 1
PS C:\Users\Administrator> $myval.gettype().fullname
System.Boolean
When working with boolean variables, the pre-defined
$true
and
$false
variables may also be used:
PS C:\Users\Administrator> [bool] $myval = $false
PS C:\Users\Administrator> $myval
False
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With