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

The link that you posted says that you need to use the -Wildcard parameter in order use wildcards.

2 Spice ups

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

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!