PowerShell Simple Switch


Example

Switch statements compare a single test value to multiple conditions, and performs any associated actions for successful comparisons. It can result in multiple matches/actions.

Given the following switch...

switch($myValue)
{
    'First Condition'    { 'First Action' }
    'Second Condition'   { 'Second Action' }
}

'First Action' will be output if $myValue is set as 'First Condition'.

'Section Action' will be output if $myValue is set as 'Second Condition'.

Nothing will be output if $myValue does not match either conditions.