Just to add more information : the $true and $false boolean literals also work as they are when used as command-line options for PowerShell (PS) scripts. For the PS script below, which is stored in a file called installmyapp.ps1 :
param ( [bool]$cleanuprequired ) echo "Batch file starting execution."
Now, if I need to call this PS file from the PS command line, here is how I can do it:
installmyapp.ps1 -cleanuprequired $true
OR
installmyapp.ps1 -cleanuprequired 1
Here 1 and $true equivalent. In addition, 0 and $false equivalent.
Note Never expect the string literal true to be automatically converted to a boolean value. For example, if I run the following command:
installmyapp.ps1 -cleanuprequired true
it cannot execute the script with the error below:
Failed to process argument conversion for 'cleanuprequired' parameter. Cannot convert the value of "System.String" to the type "System.Boolean". Logical parameters accept only logical values ββand numbers, such as $ True, $ False, 1 or 0.
RBT May 15 '18 at 8:42 2018-05-15 08:42
source share