Skip to content
ConsoleMonster
Cmdlet

New-ConsoleMenuItem

Module ConsoleMonster
Inputs
None
Outputs
ConsoleMonster.Interactive.MenuItem

Creates a menu item: an action, a submenu, a form, a selection, a page, a review, the presets list, a separator or the exit.

Syntax

New-ConsoleMenuItem [[-Action] <ScriptBlock>] [-ArgumentList <Object[]>] [-Badge <Object>] [-Describe <Object>] [-Description <String>] [-Disabled <Object>] [-Display <Object>] [-Exit] [-Form <Form>] [-GroupBy <Object>] [-Hotkey <Char>] [-Icon <String>] [-IconName <GlyphIcon>] [-LoadChoices <ScriptBlock>] [-Maximum <Int32>] [-Minimum <Int32>] [-MultiSelect <Object[]>] [-OnChange <ScriptBlock>] [-OnSubmit <ScriptBlock>] [-Page <ScriptBlock>] [-Presets] [-Preview <ScriptBlock>] [-Review <ScriptBlock>] [-Select <Object[]>] [-Selected <Object>] [-Separator] [-Single] [-State <Object>] [-Submenu <Object>] [[-Title] <String>] [<CommonParameters>]
#
Parameter set: All Parameter Sets

Description

Creates a menu item: an action, a submenu, a form, a selection, a page, a review, the presets list, a separator or the exit.

What the item does follows from the parameter you give: -Action (a scriptblock, run on the pipeline thread with $MenuContext), -Submenu (a menu or a scriptblock of items), -Form (with -OnSubmit, which gets $Values and $FormResult), -Select or -MultiSelect (the chosen objects stay on the item: $item.Selection), -LoadChoices (loaded in its own runspace with a spinner), -Page (content built each time it shows), -Review (a summary with the equivalent command and Run), -Presets, -Separator or -Exit. -Badge and -State can be scriptblocks, recomputed every time the menu draws; -Disabled returns why the item is unavailable.

Examples

Authored help example

EXAMPLE 1

New-ConsoleMenuItem -Action { }

Parameters

-Action ScriptBlock optionalposition: 1
The action, run on the pipeline thread; $MenuContext (also $_) offers Toast, Confirm, Ask, Run (a live dashboard) and ShowResult.
-ArgumentList Object[] optional
Arguments for the -LoadChoices script.
-Badge Object optional
Right-aligned text: a string, rich text, or a scriptblock recomputed whenever the menu draws.
-Describe Object optional
A sentence for the focused choice: a property name or a scriptblock.
-Description String optional
A sentence shown with the item.
-Disabled Object optional
Why the item is unavailable: a string, or a scriptblock returning the reason (nothing when available).
-Display Object optional
What to show for a choice: a property name or a scriptblock.
-Exit SwitchParameter optional
Makes the exit item (-Title defaults to Exit).
-Form Form optional
A form from New-ConsoleForm.
-GroupBy Object optional
The group of a choice: a property name or a scriptblock.
-Hotkey Char optional
The key that opens the item directly.
-Icon String optional
A short mark before the title, as free text. Prefer -IconName, which follows the glyph tier.
-IconName GlyphIcon optional
A semantic icon that follows the glyph tier: Item, Targets, Tasks, Settings, Favorite, Run, Back, List, Help, Warning, Done or Exit (for example ● in modern fonts, o in ASCII). Takes precedence over -Icon.
Possible values: Item, Targets, Tasks, Settings, Favorite, Run, Back, List, Help, Warning, Done, Exit
-LoadChoices ScriptBlock optional
Loads the choices in its own runspace (a spinner shows meanwhile). Pair with -Single for one value.
-Maximum Int32 optional
The most values of a multi-selection.
-Minimum Int32 optional
The fewest values of a multi-selection.
-MultiSelect Object[] optional
Choices for picking several values (any objects).
-OnChange ScriptBlock optional
Runs when the selection changes ($MenuContext and $_).
-OnSubmit ScriptBlock optional
Runs when the form is submitted; $Values is a hashtable of the values, $FormResult the full result.
-Page ScriptBlock optional
Page content, built each time it shows: text, rich text, widgets, or objects shown as a list.
-Presets SwitchParameter optional
Makes the item list the menu's saved presets (Enter applies one, Delete removes it).
-Preview ScriptBlock optional
Preview content for the focused choice ($_ is the choice).
-Review ScriptBlock optional
A review built each time it shows: a hashtable with Rows (an ordered hashtable of label = value), Command (the equivalent command line), Problems (strings that block running), Run (a scriptblock) and optionally Title, Description and RunText.
-Select Object[] optional
Choices for picking one value (any objects).
-Selected Object optional
Pre-selected choices: the objects or their texts, or a scriptblock returning $true for selected ones.
-Separator SwitchParameter optional
Makes a divider (with -Title as its heading, if given).
-Single SwitchParameter optional
With -LoadChoices: pick one value instead of several.
-State Object optional
State text ("24 selected"): a string or a scriptblock recomputed whenever the menu draws.
-Submenu Object optional
A submenu: a menu from New-ConsoleMenu, or a scriptblock of New-ConsoleMenuItem calls.
-Title String optionalposition: 0
The title.

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.