plugins/consoleui/src/Read-Choice.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function Global:Read-Choice {     
    Param(
        [Parameter(Position=0)]
        [System.String]$Message, 
         
        [Parameter(Position=1)]
        [ValidateNotNullOrEmpty()]
        [System.String[]]$Choices = @('&Yes','&No','Yes to &All','No &to All'),
         
        [Parameter(Position=2)]
        [System.Int32]$DefaultChoice = 0, 
         
        [Parameter(Position=3)]
        [System.String]$Title = [string]::Empty 
    )        
    [System.Management.Automation.Host.ChoiceDescription[]]$Poss = $Choices | ForEach-Object {            
        New-Object System.Management.Automation.Host.ChoiceDescription "$($_)", "Sets $_ as an answer."      
    }       
    $Host.UI.PromptForChoice( $Title, $Message, $Poss, $DefaultChoice )     
}