<\/div>\n<\/aside>\n\n
Any ideas? Probably something dumb, but it’s been a busy day, so I could use a fresh set of eyes.<\/p>","upvoteCount":4,"datePublished":"2017-11-21T20:42:24.000Z","url":"https://community.spiceworks.com/t/switch-statement-with-wildcard/620047/1","author":{"@type":"Person","name":"big-green-man","url":"https://community.spiceworks.com/u/big-green-man"}},{"@type":"Answer","text":"
Here’s an example from that KB:<\/p>\n
$a = \"d14151\"\n\nswitch -wildcard ($a) \n { \n \"a*\" {\"The color is red.\"} \n \"b*\" {\"The color is blue.\"} \n \"c*\" {\"The color is green.\"} \n \"d*\" {\"The color is yellow.\"} \n \"e*\" {\"The color is orange.\"} \n \"f*\" {\"The color is purple.\"} \n \"g*\" {\"The color is pink.\"}\n \"h*\" {\"The color is brown.\"} \n default {\"The color could not be determined.\"}\n }\n<\/code><\/pre>","upvoteCount":2,"datePublished":"2017-11-21T20:46:51.000Z","url":"https://community.spiceworks.com/t/switch-statement-with-wildcard/620047/3","author":{"@type":"Person","name":"Evan7191","url":"https://community.spiceworks.com/u/Evan7191"}},{"@type":"Answer","text":"You need to add the wildcard parameter<\/p>\n
$Username = Read-Host \"Enter Username\"\n$Grouptype = Read-Host \"Select group type: [s]ecurity, [d]istribution, or [b]oth\"\n\nswitch -Wildcard ($Grouptype) {\n \"s*\" {stuff}\n \"d*\" {stuff}\n \"b*\" {stuff}\n default {stuff}\n}\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2017-11-21T20:47:23.000Z","url":"https://community.spiceworks.com/t/switch-statement-with-wildcard/620047/4","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"Like I said, fresh eyes. Thanks, y’all!<\/p>","upvoteCount":0,"datePublished":"2017-11-21T20:57:03.000Z","url":"https://community.spiceworks.com/t/switch-statement-with-wildcard/620047/5","author":{"@type":"Person","name":"big-green-man","url":"https://community.spiceworks.com/u/big-green-man"}}]}}
I’m making a simple tool for group reporting, and I want the user to be able to either enter the first letter of their choice or the entire letter:
$Username = Read-Host "Enter Username"
$Grouptype = Read-Host "Select group type: [s]ecurity, [d]istribution, or [b]oth"
switch ($Grouptype)
{
"s*" {stuff}
"d*" {stuff}
"b*" {stuff}
default {stuff}
}
This always does the option for default, regardless of what I enter. If I remove the wildcard, it works fine for s, d, and b. Why is that? I know I can just add three more options and call it good, but Microsoft says I should be able to use wildcards:
Any ideas? Probably something dumb, but it’s been a busy day, so I could use a fresh set of eyes.
4 Spice ups
Evan7191
(Evan7191)
November 21, 2017, 8:46pm
2
The link that you posted says that you need to use the -Wildcard parameter in order use wildcards.
2 Spice ups
Evan7191
(Evan7191)
November 21, 2017, 8:46pm
3
Here’s an example from that KB:
$a = "d14151"
switch -wildcard ($a)
{
"a*" {"The color is red."}
"b*" {"The color is blue."}
"c*" {"The color is green."}
"d*" {"The color is yellow."}
"e*" {"The color is orange."}
"f*" {"The color is purple."}
"g*" {"The color is pink."}
"h*" {"The color is brown."}
default {"The color could not be determined."}
}
2 Spice ups
Neally
(Neally)
November 21, 2017, 8:47pm
4
You need to add the wildcard parameter
$Username = Read-Host "Enter Username"
$Grouptype = Read-Host "Select group type: [s]ecurity, [d]istribution, or [b]oth"
switch -Wildcard ($Grouptype) {
"s*" {stuff}
"d*" {stuff}
"b*" {stuff}
default {stuff}
}
1 Spice up
Like I said, fresh eyes. Thanks, y’all!