Interactive powershell menu
View the Project on GitHub bibistroc/powershell-interactive-menu
Install-Module -Name InteractiveMenu
This module only works in Powershell version 5.0 and up.
Sample code can be found here
# Import the module
using module InteractiveMenu
# Define the items for the menu
# Note: the url and info are optional
$menuItems = @(
[InteractiveMultiMenuItem]::new("option1", "First Option", $true, 0, $false, "First option info", "https://example.com/")
[InteractiveMultiMenuItem]::new("Option 2", "Second Option", $true, 1, $false, "Second option info", "https://example.com/")
)
# Define the header of the menu
$header = "Choose your options"
# Instantiate new menu object
$menu = [InteractiveMultiMenu]::new($header, $menuItems);
# [Optional] You can change the colors and the symbols
$options = @{
HeaderColor = [ConsoleColor]::Magenta;
HelpColor = [ConsoleColor]::Cyan;
CurrentItemColor = [ConsoleColor]::DarkGreen;
LinkColor = [ConsoleColor]::DarkCyan;
CurrentItemLinkColor = [ConsoleColor]::Black;
MenuDeselected = "[ ]";
MenuSelected = "[x]";
MenuCannotSelect = "[/]";
MenuCannotDeselect = "[!]";
MenuInfoColor = [ConsoleColor]::DarkYellow;
MenuErrorColor = [ConsoleColor]::DarkRed;
}
$menu.SetOptions($options)
# Trigger the menu and receive the user selections
$selectedItems = $menu.GetSelections()
foreach ($item in $selectedItem) {
Write-Host $item
}
# Import the module
Import-Module InteractiveMenu
# Define the items for the menu
# Note: the url, info, selected and readonly parameters are optional
$menuItems = @(
Get-InteractiveMultiMenuOption `
-Item "option1" `
-Label "First Option" `
-Order 0 `
-Info "First option info" `
-Url "https://example.com"
Get-InteractiveMultiMenuOption `
-Item "option2" `
-Label "Second Option" `
-Order 1 `
-Info "Second option info" `
-Url "https://example.com" `
-Selected `
-Readonly
)
# [Optional] You can change the colors and the symbols
$options = @{
HeaderColor = [ConsoleColor]::Magenta;
HelpColor = [ConsoleColor]::Cyan;
CurrentItemColor = [ConsoleColor]::DarkGreen;
LinkColor = [ConsoleColor]::DarkCyan;
CurrentItemLinkColor = [ConsoleColor]::Black;
MenuDeselected = "[ ]";
MenuSelected = "[x]";
MenuCannotSelect = "[/]";
MenuCannotDeselect = "[!]";
MenuInfoColor = [ConsoleColor]::DarkYellow;
MenuErrorColor = [ConsoleColor]::DarkRed;
}
# Define the header of the menu
$header = "Choose your options"
# Trigger the menu and receive the user selections
# Note: the options parameter is optional
$selectedOptions = Get-InteractiveMenuUserSelection -Header $header -Items $menuItems -Options $options
InteractiveMultiMenuItem
InteractiveMultiMenuItem([object]$itemInfo, [string]$label, [int]$order)
InteractiveMultiMenuItem([object]$itemInfo, [string]$label, [bool]$selected, [int]$order)
InteractiveMultiMenuItem([object]$itemInfo, [string]$label, [bool]$selected, [int]$order, [bool]$readonly)
InteractiveMultiMenuItem([object]$itemInfo, [string]$label, [bool]$selected, [int]$order, [bool]$readonly, [string]$info)
InteractiveMultiMenuItem([object]$itemInfo, [string]$label, [bool]$selected, [int]$order, [bool]$readonly, [string]$info, [string]$url)
[object]$ItemInfo
- The item that you want returned if the user selects it[string]$Label
- The text that you want to show for your option[int]$Order
- The order of the item in the list. You can have multiple items on the same order. The script will order them.[bool]$Selected
- If the option is selected or not by default. Possible values: $true
or $false
[bool]$Readonly
- If the option is readonly (cannot be changed). Possible values: $true
or $false
[string]$Info
- The information about the item. This information is visible if the user press I
.[string]$Url
- The URL of the item. A browser window will open on this URL if the user press O
.InteractiveMultiMenu
InteractiveMultiMenu([string]$header, [InteractiveMultiMenuItem[]]$items)
[string]$header
- The text that you want to display above the menu[InteractiveMultiMenuItem[]]$items
- The list of items to display in the menu[object[]] GetSelections()
- Execute this method to trigger the menu and get the objects that the user selected[void] SetOptions([hashtable]$options)
- Execute this method to alter the options of the menu (more details in the Options section)HeaderColor
- Color of the header. Default: [ConsoleColor]::Magenta;
HelpColor
- Color of the help items. Default: [ConsoleColor]::Cyan;
CurrentItemColor
- Color of the current selected item. Default: [ConsoleColor]::DarkGreen;
LinkColor
- Color of the links. Default: [ConsoleColor]::DarkCyan;
CurrentItemLinkColor
- Color of the current selected item link. Default: [ConsoleColor]::Black;
MenuDeselected
- Sympol for unselected item. Default: "[ ]";
MenuSelected
- Symbol for selected item. Default: "[x]";
MenuCannotSelect
- Symbol for the item that cannot be selected. Default: "[/]";
MenuCannotDeselect
- Sympol for the item that cannot be deselected. Default: "[!]";
MenuInfoColor
- Color of the item information. Default: [ConsoleColor]::DarkYellow;
MenuErrorColor
- Color of the errors. Default: [ConsoleColor]::DarkRed;