How to declare a variable and its type is Boolean in PowerShell? [duplicate] How to declare a variable and its type is Boolean in PowerShell? [duplicate] powershell powershell

How to declare a variable and its type is Boolean in PowerShell? [duplicate]


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 = 1PS C:\Users\Administrator> $myval.gettype().fullnameSystem.Boolean

When working with boolean variables, the pre-defined

$true

and

$false

variables may also be used:

PS C:\Users\Administrator> [bool] $myval = $falsePS C:\Users\Administrator> $myvalFalse