Skip to content

Instantly share code, notes, and snippets.

@gerane
Last active May 23, 2016 18:16
Show Gist options
  • Save gerane/b40a4755fc249ed420c49ae8fef947f9 to your computer and use it in GitHub Desktop.
Save gerane/b40a4755fc249ed420c49ae8fef947f9 to your computer and use it in GitHub Desktop.
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
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