Powershell 开关语句不适用于 or 运算符



试图让我的switch语句在其中使用"-or"运算符。我做错了什么?

法典:

PS C:Windowssystem32> $a = 1031
PS C:Windowssystem32> switch ($a) {1031 {write "True"}}
True
PS C:Windowssystem32>
PS C:Windowssystem32>
PS C:Windowssystem32> switch ($a) {((1031) -or (2055)) {write "True"}}
PS C:Windowssystem32>

你需要使用脚本块,$_是你打开的值(例如$a(:

switch ($a) 
{
    {$_ -eq 1031 -or $_ -eq 2055} {write "True"}
}

最新更新