Skip to content
ConsoleMonster
Cmdlet

Read-ConsoleSelect

Module
ConsoleMonster
Inputs
System.Object[]

Asks the user to pick one of the choices and returns the chosen object.

Syntax

Read-ConsoleSelect
[-Badge <Object>]
[[-Choices] <Object[]>]
[-Default <Object>]
[-Describe <Object>]
[-Description <String>]
[-DisabledReason <ScriptBlock>]
[-Display <Object>]
[-GroupBy <Object>]
[-Hotkey <Object>]
[-Mode <Rich|Line|Accessible>]
[-PageSize <Int32>]
[-ParameterName <String>]
[-Preview <ScriptBlock>]
[-StaticSnapshot]
[-Title] <String>
[<CommonParameters>]
#
Parameter set: All Parameter Sets

Description

Typing filters the list (fuzzy, matches highlighted). Choices can be grouped (-GroupBy), described (-Describe, shown for the focused choice), tagged (-Badge), picked by a key (-Hotkey; '/' then filters), disabled with a reason (-DisabledReason) and previewed (-Preview, beside the list when the window is wide). The chosen object itself is returned (a service, a record), not its text. In remoting and the ISE the choices are numbered and the host reads the answer.

Examples

Example 1

$service = Get-Service | Read-ConsoleSelect 'Service to restart' -Display DisplayName -Describe Name -GroupBy Status

Pick a service

Example 2

$environment = Read-ConsoleSelect 'Environment' -Choices 'Production', 'Staging', 'Lab' -Default 'Staging'

Strings with a default

Parameters

-Badge Object optional
Short right-aligned text per choice: a property name or a scriptblock.
-Choices Object[] optionalposition: 1pipeline: True (ByValue)
The choices: any objects (strings, services, records). The chosen objects themselves are returned.
-Default Object optional
The default: one of the choices, or its displayed text.
-Describe Object optional
A sentence for the focused choice: a property name or a scriptblock.
-Description String optional
Help text under the question.
-DisabledReason ScriptBlock optional
Returns why a choice is unavailable ($_ is the choice), or nothing when it is available.
-Display Object optional
What to show for a choice: a property name or a scriptblock ($_ is the choice). Default: the choice as text.
-GroupBy Object optional
The group heading of a choice: a property name or a scriptblock.
-Hotkey Object optional
A key that picks a choice directly: a property name or a scriptblock returning a letter.
-Mode InteractionMode optional
Forces how to ask: Rich (in-place prompt), Line (question and typed answer), Accessible (numbered, no redraws) or None (use the default or fail).
Possible values: Rich, Line, Accessible
-PageSize Int32 optional
The preferred number of visible rows.
-ParameterName String optional
The parameter of your script that supplies this value without a prompt (named in the non-interactive error, for example -Domain).
-Preview ScriptBlock optional
Content for the preview pane ($_ is the focused choice): text, rich text, a widget, or an object shown as a list.
-StaticSnapshot SwitchParameter optional
Prints the initialized rich prompt without reading input or returning an answer. Useful for documentation and unattended previews.
-Title String requiredposition: 0
The question.

Common Parameters

This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.

For more information, see about_CommonParameters.