Skip to content

Write-Menu

SYNOPSIS

Outputs a command-line menu which can be navigated using the keyboard.

SYNTAX

Write-Menu [-Entries] <Object> [[-Title] <String>] [-Sort] [-MultiSelect] [<CommonParameters>]

DESCRIPTION

Outputs a command-line menu which can be navigated using the keyboard.

  • Automatically creates multiple pages if the entries cannot fit on-screen.
  • Supports nested menus using a combination of hashtables and arrays.
  • No entry / page limitations (apart from device performance).
  • Sort entries using the -Sort parameter.
  • -MultiSelect: Use space to check a selected entry, all checked entries will be invoked / returned upon confirmation.
  • Jump to the top / bottom of the page using the "Home" and "End" keys.
  • "Scrolling" list effect by automatically switching pages when reaching the top/bottom.
  • Nested menu indicator next to entries.
  • Remembers parent menus: Opening three levels of nested menus means you have to press "Esc" three times.

Controls Description -------- ----------- Up Previous entry Down Next entry Left / PageUp Previous page Right / PageDown Next page Home Jump to top End Jump to bottom Space Check selection (-MultiSelect only) Enter Confirm selection Esc / Backspace Exit / Previous menu

EXAMPLES

EXAMPLE 1

$menuReturn = Write-Menu -Title 'Menu Title' -Entries @('Menu Option 1', 'Menu Option 2', 'Menu Option 3', 'Menu Option 4')

Output:

Menu Title

Menu Option 1 Menu Option 2 Menu Option 3 Menu Option 4

EXAMPLE 2

$menuReturn = Write-Menu -Title 'AppxPackages' -Entries (Get-AppxPackage).Name -Sort

This example uses Write-Menu to sort and list app packages (Windows Store/Modern Apps) that are installed for the current profile.

EXAMPLE 3

$menuReturn = Write-Menu -Title 'Advanced Menu' -Sort -Entries @{

'Command Entry' = '(Get-AppxPackage).Name' 'Invoke Entry' = '@(Get-AppxPackage).Name' 'Hashtable Entry' = @{ 'Array Entry' = "@('Menu Option 1', 'Menu Option 2', 'Menu Option 3', 'Menu Option 4')" } }

This example includes all possible entry types:

Command Entry Invoke without opening as nested menu (does not contain any prefixes) Invoke Entry Invoke and open as nested menu (contains the "@" prefix) Hashtable Entry Opened as a nested menu Array Entry Opened as a nested menu

PARAMETERS

-Entries

Array or hashtable containing the menu entries

Type: Object
Parameter Sets: (All)
Aliases: InputObject

Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-Title

Title shown at the top of the menu.

Type: String
Parameter Sets: (All)
Aliases: Name

Required: False
Position: 2
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-Sort

Sort entries before they are displayed.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-MultiSelect

Select multiple menu entries using space, each selected entry will then get invoked (this will disable nested menu's).

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

NOTES

Write-Menu by QuietusPlus (inspired by "Simple Textbased Powershell Menu" [Michael Albert])

https://quietusplus.github.io/Write-Menu

https://github.com/QuietusPlus/Write-Menu