Goal: When the user enters in a color not in the list, it should default to gray. If the user chooses a color in the list that color should be used.
What is actually happening: Color is always defaulting to gray.
Plain text example 1: Choose a color: yellow, green, red, purple or gray. User: Blue. Output: Color is gray.
Plain text example 2: Choose a color: yellow, green, red, purple or gray. User: Green. Output: Color is Green.
[CmdletBinding()]
param (
[Parameter(Mandatory=$True, HelpMessage="Choose yellow, green, red, purple or gray")]
[string]$color_select
)
$colors_list = "yellow", "green", "red", "purple", "gray", "random"
if ($color_select -notcontains $colors_list) {
$color_select = "gray"
}
Write-host "The color is: $color_select"
Aucun commentaire:
Enregistrer un commentaire