Hi,
I need help dynamically creating switch statement selections.
I can do this OK.
$ar = "RED","GREEN"
$ANS = (Read-Host "Choose from these $ar")
Choose from options RED GREEN: RED
$ANS
RED
switch ($ANS){
GREEN {write-host "GREEN"}
RED {write-host "RED"}
default {write-host "NO GOOD"}
}
RED
But What if I want to dynamically populate the choices of Red and Green from the $ar array? It does not work. For example if I replace this..
"GREEN {write-host "GREEN"}
RED {write-host "RED"}"
with this..
"foreach($y in $ar){
$y
{write-host "$y"}
}"
Purpose to dynamically create the menu contents based on the array and provide actions based on those. My contents are never static.
I assume I can dynamically populate these somehow but I get an error..
Missing statement block in switch statement clause.
Any ideas?