$a = "lp-lon-5673"
switch ($a) {
"lp-lon*" {"It is London Laptop."}
"lp-rom*" {"It is Romania Laptop."}
{($_ -eq "lp-sing*") -or ($_ -eq "LP-USA*")} {"It is a singapore or USA Laptop"}
4 {"It is four."}
}
$a = "LP-USA-12312"
switch -Wildcard ($a) {
"lp-lon*" {"It is London Laptop."}
"lp-rom*" {"It is Romania Laptop."}
{($_ -eq "lp-sing*") -or ($_ -eq "LP-USA*")} {"It is a singapore or USA Laptop"}
4 {"It is four."}
}
$a = "LP-USA-12312"
switch -Wildcard ($a) {
"lp-lon*" {"It is London Laptop."}
"lp-rom*" {"It is Romania Laptop."}
{($_ -like "lp-sing*") -or ($_ -like "LP-USA*")} {"It is a singapore or USA Laptop"}
4 {"It is four."}
}
eq becomes like which supports wildcards.
$a = "LP-USA-12312"
switch -RegEx ($a) {
'lp-lon.*' {"It is London Laptop."}
'lp-rom.*' {"It is Romania Laptop."}
'lp-sing.*|lp-usa.*' {"It is a singapore or USA Laptop"}
4 {"It is four."}
}
switch ("Match me") {
"Match me" {"1st match"}
"Match me" {"2nd match"}
"Match me" {"woe is me it just keeps going"}
default {"unmatched"}
}
switch ("Match me") {
"Match me" {"1st match"; break}
"Match me" {"2nd match"; break}
"Match me" {"woe is me it just keeps going"; break}
default {"unmatched"}
}
Switch has a wildcard parameter though.
Open in new window
It can also do regular expressions (RegEx) parameter if you need something more advanced.