Skip to content

Read-SpectreMultiSelectionGrouped

Description

Displays a multi-selection prompt with grouped choices and returns the selected choices. The prompt allows the user to select one or more choices from a list of options. The choices can be grouped into categories, and the user can select choices from each category.


Examples

Example 1
This example demonstrates a multi-selection prompt with grouped choices.

$selected = Read-SpectreMultiSelectionGrouped -Message "Select your favorite colors" -PageSize 8 -Choices @(
    @{
        Name = "Primary Colors"
        Choices = @("Red", "Blue", "Yellow")
    },
    @{
        Name = "Secondary Colors"
        Choices = @("Green", "Orange", "Purple")
    }
)
# Type "↓", "<space>", "↓", "↓", "↓", "<space>", "↲" to choose red and all secondary colors
Write-SpectreHost "Your favourite colors are $($selected -join ', ')"

Parameters

Message

The title of the prompt. The default value is “What are your favourite [Spectre.Console.Color]?“.

TypeRequiredPositionPipelineInputAliases
[String]false1falseTitle
Question
Prompt

Choices

An array of choice groups. Each group is a hashtable with two keys: “Name” and “Choices”. The “Name” key is a string that represents the name of the group, and the “Choices” key is an array of strings that represents the choices in the group.

TypeRequiredPositionPipelineInput
[Array]true2false

ChoiceLabelProperty

The name of the property to use as the label for each choice. If this parameter is not specified, the choices are displayed as strings.

TypeRequiredPositionPipelineInput
[String]false3false

Color

The color of the selected choices. The default value is the accent color of the script.

TypeRequiredPositionPipelineInput
[Color]false4false

PageSize

The number of choices to display per page. The default value is 10.

TypeRequiredPositionPipelineInput
[Int32]false5false

TimeoutSeconds

TypeRequiredPositionPipelineInput
[Int32]false6false

AllowEmpty

Allow the multi-selection to be submitted without any options chosen.

TypeRequiredPositionPipelineInput
[Switch]falsenamedfalse

Syntax

Read-SpectreMultiSelectionGrouped [[-Message] <String>] [-Choices] <Array> [[-ChoiceLabelProperty] <String>] [[-Color] <Color>] [[-PageSize] <Int32>] [[-TimeoutSeconds] <Int32>] [-AllowEmpty] [<CommonParameters>]