I'm trying to find a way to use an array of items, with wildcards, as a condition in a switch statement, and not having much success. Here's an example of what I'm trying to do,
$pcModel = "HP ProDesk 800 G5"
switch -Wildcard ($pcModel.ToUPPER()) {
"*PROBOOK*" {
#Do something
Break
}
"*ELITEBOOK*" {
#Do something else
Break
}
{$_ -in "*ELITEDESK*", "*PRODESK*", "*ELITEONE*" }{
# have also tried
#{$_ -eq "*ELITEDESK*", "*PRODESK*", "*ELITEONE*" }
#{"*ELITEDESK*", "*PRODESK*", "*ELITEONE*" -eq $_ }
#{"*ELITEDESK*", "*PRODESK*", "*ELITEONE*" -like $_ }
#{@("*ELITEDESK*", "*PRODESK*", "*ELITEONE*") -contains $_ }
# Do other things
Break
}
Default{
# do nothing
Break
}
}
As I've commented in the code, I've tried numerous incarnations of an array with wildcards as a condition with no success. The condition always fails What am I missing. Before anyone chastises me for using ToUPPER because the switch statement is case insensitive, in this specific example I've found that to be false.
-wildcard, use-regex. A regular expression allows you to construct "A or B" type matches using the|:'ELITEDESK|PRODESK|ELITEONE'.