OpsaC - Operating as PowerShell code
published: June 23, 2016 author: Tinu tags: Switch - ValidateSet categories: PowerShell
If all you want is limiting choices, you can use a ValidateSet attribute instead.
#requires -Version 2
function Select-City
{
param
(
[ValidateSet('Bern','Zürich','Chur','Lugano')]
[Parameter(Mandatory=$true)][String]$City
)
switch ($City)
{
'Bern' {"The Gurten is in $City"}
'Zürich' {"The Uetliberg is in $City"}
'Chur' {"The Brambrüesch is in $City"}
'Lugano' {"The Monte San Salvatore is in $City"}
}
}
Select-City