Please ignore my first answer; this is not the answer, as I see it now. And thanks for the really interesting question.
, . . Get-Choice.ps1 Get-Choice2.ps1:
<
.SYNOPSIS
Displays PowerShell style menu and gets user choices
.DESCRIPTION
*) Returns choice indexes.
*) Choice keys are indicated by '&' in menu items.
*) Help strings can be empty or nulls (items are used themselves).
param
(
[string]$Caption = 'Confirm',
[string]$Message = 'Are you sure you want to continue?',
[string[]]$Choices = ('&Yes', 'Continue', '&No', 'Stop'),
[int[]]$DefaultChoice = @(0)
)
if ($args) { throw "Unknown parameters: $args" }
if ($Choices.Count % 2) { throw "Choice count must be even." }
$descriptions = @()
for($i = 0; $i -lt $Choices.Count; $i += 2) {
$c = [System.Management.Automation.Host.ChoiceDescription]$Choices[$i]
$c.HelpMessage = $Choices[$i + 1]
if (!$c.HelpMessage) {
$c.HelpMessage = $Choices[$i].Replace('&', '')
}
$descriptions += $c
}
$Host.UI.PromptForChoice($Caption, $Message, [System.Management.Automation.Host.ChoiceDescription[]]$descriptions, $DefaultChoice)
:
Get-Choice2 'Title' 'Message' -DefaultChoice 0, 1, 2 -Choices @(
'Choice &1', 'This is choice 1'
'Choice &2', ''
'Choice &3', ''
'Choice &4', ''
'Choice &5', ''
'Choice &6', ''
'Choice &7', ''
'Choice &8', ''
'Choice &9', ''
'Choice &0', ''
)
10 , 3 ( ) :
0> Test-Get-Choice2.ps1
Title
Message
[1] Choice 1
[2] Choice 2
[3] Choice 3
[4] Choice 4
[5] Choice 5
[6] Choice 6
[7] Choice 7
[8] Choice 8
[9] Choice 9
[0] Choice 0
[?] Help
(default choices are 1,2,3)
Choice[0]:
Enter, : 0, 1, 2. , : 5 + Enter + 3 + Enter + 1 + Enter + Enter, 4, 2, 0.
. PowerShell ISE , , , - .