PowerShell Function If Else Selection (Example)
26. August 2012 | In: PowerShell
## Function PS Read-Host Select Example## Function myfunction { $path = "yourpath" $1 = "1. One" $2 = "2. Two" $3 = "3. Three" $x = "Exit" write-host "$1" write-host "$2" write-host "$3" $Selection = Read-Host "Please Select (1-3) or Exit (x)" cls ## Selection Handling if ($Selection -eq "1") { "you selecting $1" $path = "$path\$1" "$path" } elseif ($Selection -eq "2") { ".... you selecting $2" $path = "$path\$2" "$path" } elseif ($Selection -eq "3") { ".... you selecting $3" $path = "$path\$3" "$path" } ## Exit condition elseif ($Selection -eq "x") { exit } ## No Valid Selection elseif ($Selection -ge $null) { "---------------------------------------------------" write-host " no valid Selection! Please Select again" "---------------------------------------------------" # myfunction } } ## End Function Select ## ## Run Function ## myfunction