Feed choice menu with options

07/01/2012 01:36

#Feed choice menu with options.


function SelectChoice
{
        param(
        [array]$options
        )


if(($options.length -gt 1))
    {
        write-host "======================================================="
        write-host "There are more options of parameter, choose the number."
        write-host "======================================================="
        for($i=0; $i -le $options.length-1; $i++)
            {
                write-host ($i+1) ". " $options[$i]
            }
        $index=read-host "Select the option number."
        #write-host "You selected number "$index " with value " $options[$index-1]
        $result=$options[$index-1]
        return $result
   
    }
 else
 {
    #write-host "They are no choices, only this one value: "$options[0]
    $result=$options[0]
    return $result
 }   
}

#array input
$pole=1, 2, 10, 16
$a=SelectChoice -options $pole
write-host "Call result: "$a

#collection input
$c=get-childitem
$b=SelectChoice -options $c
write-host "Call result: "$b

#single value input
$single=88
$d=SelectChoice -options $single
write-host "Call result: "$d