New-ConsoleMenuItem
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
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
EXAMPLE 1
New-ConsoleMenuItem -Action { }Parameters
- -Action ScriptBlock
- The action, run on the pipeline thread; $MenuContext (also $_) offers Toast, Confirm, Ask, Run (a live dashboard) and ShowResult.
- -ArgumentList Object[]
- Arguments for the -LoadChoices script.
- -Badge Object
- Right-aligned text: a string, rich text, or a scriptblock recomputed whenever the menu draws.
- -Describe Object
- A sentence for the focused choice: a property name or a scriptblock.
- -Description String
- A sentence shown with the item.
- -Disabled Object
- Why the item is unavailable: a string, or a scriptblock returning the reason (nothing when available).
- -Display Object
- What to show for a choice: a property name or a scriptblock.
- -Exit SwitchParameter
- Makes the exit item (-Title defaults to Exit).
- -Form Form
- A form from New-ConsoleForm.
- -GroupBy Object
- The group of a choice: a property name or a scriptblock.
- -Hotkey Char
- The key that opens the item directly.
- -Icon String
- A short mark before the title, as free text. Prefer -IconName, which follows the glyph tier.
- -IconName GlyphIcon
- 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
- Loads the choices in its own runspace (a spinner shows meanwhile). Pair with -Single for one value.
- -Maximum Int32
- The most values of a multi-selection.
- -Minimum Int32
- The fewest values of a multi-selection.
- -MultiSelect Object[]
- Choices for picking several values (any objects).
- -OnChange ScriptBlock
- Runs when the selection changes ($MenuContext and $_).
- -OnSubmit ScriptBlock
- Runs when the form is submitted; $Values is a hashtable of the values, $FormResult the full result.
- -Page ScriptBlock
- Page content, built each time it shows: text, rich text, widgets, or objects shown as a list.
- -Presets SwitchParameter
- Makes the item list the menu's saved presets (Enter applies one, Delete removes it).
- -Preview ScriptBlock
- Preview content for the focused choice ($_ is the choice).
- -Review ScriptBlock
- 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[]
- Choices for picking one value (any objects).
- -Selected Object
- Pre-selected choices: the objects or their texts, or a scriptblock returning $true for selected ones.
- -Separator SwitchParameter
- Makes a divider (with -Title as its heading, if given).
- -Single SwitchParameter
- With -LoadChoices: pick one value instead of several.
- -State Object
- State text ("24 selected"): a string or a scriptblock recomputed whenever the menu draws.
- A submenu: a menu from New-ConsoleMenu, or a scriptblock of New-ConsoleMenuItem calls.
- -Title String
- 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.