I think I'm missing something obvious here. In my understanding a Boolean
can only be 0
, $False
, 1
or $True
. But when I try other integers, they are also accepted as $True
.
When using other integers then 0
or 1
the function should throw an error saying that it's not a Boolean
. Or should this be solved by adding error handling with ValidateSet
for these 4 different input options?
Example:
Function Test-Bar {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=0)]
[Bool]$Var
)
Write-Host "Yes, you entered a valid boolean: $Var" -ForegroundColor Yellow
}
[INT]$Number = '0'
Test-Bar -Var $Number
[INT]$Number = '1'
Test-Bar -Var $Number
[INT]$Number = '10'
Test-Bar -Var $Number # Incorrect, ten is not a boolean
[INT]$Number = '22'
Test-Bar -Var $Number # Incorrect, twenty two is not a boolean
Thank you for your help.