Skip to content
ConsoleMonster
Cmdlet

Show-ConsoleMenu

Module
ConsoleMonster
Inputs
System.Management.Automation.PSObject

Shows a menu until the user exits.

Syntax

Show-ConsoleMenu
[-AppName <String>]
[-Layout <Auto|Classic|Shell|Inline>]
[[-Menu] <PSObject>]
[-Mode <Rich|Line|Accessible|Snapshot>]
[-NoCommandPalette]
[-RememberLastChoices]
[-StorageRoot <String>]
[<CommonParameters>]
#
Parameter set: All Parameter Sets

Description

Menu actions run on the pipeline thread. Selections and form values survive navigation. AppName stores presets, and RememberLastChoices also stores the last choices.

Shell menu ----------

The title bar shows the breadcrumb. The sidebar lists items and folds into the breadcrumb in narrow windows. The content pane shows the open list, form, page or review. The footer lists the current keys. Use Escape to go back and Ctrl+Q to exit.

Classic menu ------------

Classic shows a centred menu. Escape returns from a submenu and exits from the root. Both full-screen layouts show the key map with ?. When enabled, Ctrl+K opens the command palette. A colon also opens it when focus is outside a text input. Ctrl+Q asks before discarding unsaved form edits.

Inline menu -----------

Inline displays one selection prompt at a time in the scrollback. In line mode, respond with the numbered choice. Actions write their output in the scrollback and the menu returns after the action. Use Back in a submenu or choose an Exit item to leave.

Static menu -----------

Mode None prints the current menu once without executing actions. A session started with PowerShell's NonInteractive switch also prints a static menu if no input source is supplied. Scripted input, such as keys supplied by Invoke-ConsoleHeadless, can still drive the menu and run actions in that session. Redirected output and CI use static output when there is no input source. Explicit Mode Line uses the host for input, so with an interactive host it can still prompt and run actions in CI or with redirected output.

Examples

Example 1

$menuOptions2 = @{
    Title = 'Server toolbox'
    Content = {
        $menuItemOptions = @{
            Label = 'Current time'
            Action = { $MenuContext.Toast((Get-Date).ToString('u')) }
        }
        New-ConsoleMenuItem @menuItemOptions
        New-ConsoleMenuItem -Exit
    }
}
$menu = New-ConsoleMenu @menuOptions2
$menuOptions = @{
    Menu = $menu
    Layout = 'Shell'
}
Show-ConsoleMenu @menuOptions

Run a menu as an application

Example 2

$menuOptions2 = @{
    Title = 'Inventory'
    Content = {
        $menuItemOptions = @{
            Label = 'List servers'
            Action = { [pscustomobject]@{ Name = 'web01'; State = 'Online' } | Show-ConsoleTable }
        }
        New-ConsoleMenuItem @menuItemOptions
        New-ConsoleMenuItem -Exit
    }
}
$menu = New-ConsoleMenu @menuOptions2
$menuOptions = @{
    Menu = $menu
}
Show-ConsoleMenu @menuOptions

Choose an inventory action from a menu

Example 3

Get-ConsoleDemo -Slug 'toolbox' | Select-Object -ExpandProperty Source
Get-ConsoleDemo -Slug 'fleet' | Select-Object -ExpandProperty Source

Read any of these gallery scripts to see Show-ConsoleMenu in a complete example. Each lookup returns the script's source. Use the same slug with Show-ConsoleDemo to run it.

Parameters

-AppName String optional
The app name presets and remembered choices are stored under (default: the menu title).
-Layout MenuLayout optional
The layout: Auto (the menu's own, or Shell when items open content), Classic, Shell or Inline.
Possible values: Auto, Classic, Shell, Inline
-Menu PSObject optionalposition: 0pipeline: True (ByValue)
The menu from New-ConsoleMenu.
-Mode InteractionMode optional
Forces how to interact: Rich, Line or Accessible.
Possible values: Rich, Line, Accessible, Snapshot
-NoCommandPalette SwitchParameter optional
Turns the command palette off.
-RememberLastChoices SwitchParameter optional
Remembers selections and form answers between runs.
-StorageRoot String optional
The folder that holds the app's storage folder (default: per user).

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.