更新时间:2023-11-07 18:52:28
使用-as
时要小心.仅当字符串为0
或1
时有效.
Be careful with -as
. It only works when a string is 0
or 1
.
("FALSE") -as [bool]
和[bool]("FALSE")
都将返回True
!
***使用
[System.Convert]::ToBoolean("FALSE")
[System.Convert]::ToBoolean("False")
[System.Convert]::ToBoolean(0)
或解析
[bool]::Parse("FALSE")
[bool]::TryParse("FALSE", $outputVariable) # Will not raise an exception if the parse fails
Parse
仅将字符串作为参数使用.
Parse
only works with strings as parameter.