Anyone know how I can have a switch statement with multiple possible values like the example below?
switch ($myNumber) {
1 3 5 7 9 { write-host "Odd" }
2 4 6 8 10 {write-host "Even" }
}
Used to be easy in VBScript, so I'm sure i'm just missing something simple.
e.g in VBScript
Select Case myNumber
Case 1,3,5,7,9
MsgBox "Odd"
Case 2,4,6,8,10
MsgBox "Even"
End Select
Cheers in advance,
Ben
In your case you can simply use
An actual attempt to model what you can do there in VB would probably be something like
Adding this for completeness...
The closest PowerShell code to the above VB script is:
Because the VB script Select Case operates via an OR
"If testexpression matches any Case expressionlist expression, the statements following that Case clause are executed up to the next Case clause..." Select Case Statement
The interesting thing that I have not been able to figure out is this result:
How about this for an easy alternative using regex?