powershellswitch-statement

What's the PowerShell syntax for multiple values in a switch statement?


I basically want to do this:

switch($someString.ToLower())
{
    "y", "yes" { "You entered Yes." }
    default { "You entered No." }
}

Solution

  • switch($someString.ToLower()) 
    { 
        {($_ -eq "y") -or ($_ -eq "yes")} { "You entered Yes." } 
        default { "You entered No." } 
    }