-
-
Save gerane/b40a4755fc249ed420c49ae8fef947f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-CommandChoice | |
{ | |
[CmdletBinding()] | |
param | |
( | |
[Parameter(Mandatory=$true)] | |
[Array]$Array, | |
[Parameter(Mandatory=$true)] | |
[string]$caption, | |
[Parameter(Mandatory=$true)] | |
[string]$Message, | |
[int]$Defaults | |
) | |
Process | |
{ | |
$Choices = [System.Management.Automation.Host.ChoiceDescription[]] @($Array) | |
$Selections = $host.ui.PromptForChoice($Caption, $Message, $Choices, $Defaults) | |
foreach ($Selection in $Selections) | |
{ | |
$Array[$Selection] | |
} | |
} | |
} | |
$Extensions = @('Git','Pester','Psake','None') | |
$Caption = "Please select a single Option" | |
$Message = "This prompts like it should" | |
$CommandChoice = Get-CommandChoice -Array $Extensions -caption $Caption -Message $Message -Defaults '0' | |
$CommandChoice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-CommandChoice | |
{ | |
[CmdletBinding()] | |
param | |
( | |
[Parameter(Mandatory=$true)] | |
[Array]$Array, | |
[Parameter(Mandatory=$true)] | |
[string]$caption, | |
[Parameter(Mandatory=$true)] | |
[string]$Message, | |
[int[]]$Defaults | |
) | |
Process | |
{ | |
$Choices = [System.Management.Automation.Host.ChoiceDescription[]] @($Array) | |
$Selections = $host.ui.PromptForChoice($Caption, $Message, $Choices, $Defaults) | |
foreach ($Selection in $Selections) | |
{ | |
$Array[$Selection] | |
} | |
} | |
} | |
$Extensions = @('Git','Pester','Psake','None') | |
$Caption = "Please select multiple Options" | |
$Message = "Having [int[]] instead of [int] for Defaults breaks prompt" | |
$CommandChoice = Get-CommandChoice -Array $Extensions -caption $Caption -Message $Message -Defaults '0','1','2' | |
$CommandChoice |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment