2

Trying to get my switch statement working with an "-or" operater in it.. What am i doing wrong?

Code:

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 Answer 1

3

You need to use a scriptblock, $_ is the value you're switching on (e.g $a):

switch ($a) 
{
    {$_ -eq 1031 -or $_ -eq 2055} {write "True"}
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.