PowerShell Switch Statement with Wildcard Parameter


Example

The -Wildcard parameter allows switch statements to perform wildcard matching against conditions.

Example:

switch -Wildcard ('Condition')
{ 
    'Condition'           {'Normal match'}
    'Condit*'             {'Zero or more wildcard chars.'} 
    'C[aoc]ndit[f-l]on'   {'Range and set of chars.'}  
    'C?ndition'           {'Single char. wildcard'}
    'Test*'               {'No match'} 
}

Output:

Normal match
Zero or more wildcard chars.
Range and set of chars.
Single char. wildcard