An example of what I want to do:
enum Fruit {
Apple
Banana
Orange
}
$myFruit = [Fruit]::$UsrString
switch ($myFruit) {
Apple, Orange {
Write-Host "This is an apple or an orange"
break
}
Banana {
Write-Host "This is a banana"
break
}
default {
Write-Host "Unknown fruit: $myFruit"
break
}
}
But each attempt I have made has yet to work as intended, if at all.
I have searched for anything to do with Powershell, switch-statements, and enums but have yet to find the answer.
I have reviewed this link on StackOverflow.
I have successfully used the "switch -regEx (someEnum)" as long as I use the integer values of the enum items. However, that essentially defeats the use of the enum (ie. labeled ints).
My intent was to keep the switch as efficient as possible (ie. switching on simple int values; staying away from the more common string-compare style PS switch usage, just to keep performance up).
Does the multi-item case block syntax exist for enum usage in powershell?
Thanks in advance for any information.