Question:
I’m writing a code at the moment where I want to install network-shared printers automatically. Which printer the script should install depends on whether a user works for example in Sales or HR. I wanted to solve this problem with a switch
statement, but the problem is that it always matches the first value.
I tried several combinations of continue- or break-points, but none of them lead to my desired result.
1 2 3 4 5 6 7 8 |
$a = "HR" switch ($a) { {"Marketing", "Sales"} { "1" } {"Sales Department", "HR"} { "2" } "EDV" { "3" } } |
Output:
1 2 |
1 2 |
Normally, the console output should be “2”, but it is “1” “2”.
Answer:
Change the condition block to:
1 2 |
{$_ -in "Marketing", "Sales"} |
This way both terms will match the switch case