2013-10-08 27 views
1

試圖讓我的switch語句與「-or」操作符一起工作.. 我在做什麼錯了?Powershell switch語句不能與or-operator一起使用

代碼:

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

回答

1

你需要使用一個腳本塊,$_爲你接通值(例如$ A):

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