Tinus EngOps Wiki

Logo

OpsaC - Operating as PowerShell code

Links

Home

IT-Wiki

PowerShell Blog

PowerShell Index

PowerShell Search

Additional Websites

View my GitHub Profile

View my GitHub Gists

View my Codeberg Page

View my Photo Website

ValidateSet

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

← Previous Post ◇ [ Top ] ◇ Copyright © 2024 by tinuwalther ◇ [ Blog ] ◇ Next Post →