Skip to content
ConsoleMonster
Cmdlet

New-ConsoleMenu

Module
ConsoleMonster
Inputs
System.Management.Automation.PSObject
Outputs
ConsoleMonster.Interactive.Menu

Creates a menu from items (New-ConsoleMenuItem) for Show-ConsoleMenu.

Syntax

New-ConsoleMenu
[[-Content] <ScriptBlock>]
[-Description <String>]
[-InputObject <PSObject>]
[-Layout <Auto|Classic|Shell|Inline>]
[-Preset <Object[]>]
[-Subtitle <String>]
[-Title] <String>
[<CommonParameters>]
#
Parameter set: All Parameter Sets

Description

The scriptblock runs once and its New-ConsoleMenuItem output becomes the items, in order. A menu can be shown as an app (Shell: title bar with the breadcrumb, sidebar, content pane, key footer), a centred menu (Classic) or a list in the scrollback (Inline); the layout can be set here or on Show-ConsoleMenu. Presets the app comes with (New-ConsoleMenu -Preset, emitted in the scriptblock or given with -Preset) are listed first by a New-ConsoleMenuItem -Presets item, marked as built in.

Examples

Example 1

$formOptions = @{
    Title = 'Settings'
    Content = {
        $fieldOptions2 = @{
            Key = 'Target'
            Label = 'Target'
            Default = 'Weekly'
        }
        New-ConsoleField @fieldOptions2
        $fieldOptions = @{
            Key = 'Compress'
            Label = 'Compress'
            Kind = 'Toggle'
            Default = $true
        }
        New-ConsoleField @fieldOptions
    }
}
$settings = New-ConsoleForm @formOptions
$menuOptions2 = @{
    Title = 'Backup helper'
    Content = {
        $menuItemOptions2 = @{
            Label = 'Preview backup'
            Hotkey = 'b'
            Action = {
                $dashboardOptions = @{
                    Title = 'Backup preview'
                    Content = {
                        $statusListOptions = @{
                            WidgetId = 'steps'
                            Content = { 'Inspect plan' }
                        }
                        New-ConsoleStatusList @statusListOptions
                    }
                }
                $dashboard = New-ConsoleDashboard @dashboardOptions
                $null = $MenuContext.Run($dashboard, {
                        $updateConsoleOptions = @{
                            WidgetId = 'steps'
                            Key = 'Inspect plan'
                            Status = 'Pass'
                        }
                        Update-Console @updateConsoleOptions
                        @{ Title = 'Backup preview'; Status = 'Pass'; Summary = 'No files were copied.' }
                    })
            }
        }
        New-ConsoleMenuItem @menuItemOptions2
        $menuItemOptions = @{
            Label = 'Settings'
            Hotkey = 's'
            Form = $settings
        }
        New-ConsoleMenuItem @menuItemOptions
        New-ConsoleMenuItem -Exit
    }
}
$menu = New-ConsoleMenu @menuOptions2
$menuOptions = @{
    Menu = $menu
    Layout = 'Classic'
}
Show-ConsoleMenu @menuOptions

Build a small script menu

Example 2

$formOptions = @{
    Title = 'Settings'
    Content = {
        $fieldOptions2 = @{
            Key = 'Target'
            Label = 'Target'
            Default = 'Weekly'
        }
        New-ConsoleField @fieldOptions2
        $fieldOptions = @{
            Key = 'Compress'
            Label = 'Compress'
            Kind = 'Toggle'
            Default = $true
        }
        New-ConsoleField @fieldOptions
    }
}
$settings = New-ConsoleForm @formOptions
$menuOptions2 = @{
    Title = 'Backup helper'
    Content = {
        [pscustomobject]@{ Name = 'Weekly'; Form = $settings; Values = @{ Target = 'Weekly'; Compress = $true }; Description = 'The Sunday backup.' }
        $menuItemOptions2 = @{
            Presets = $true
            Label = 'Presets'
            Hotkey = 'p'
        }
        New-ConsoleMenuItem @menuItemOptions2
        $menuItemOptions = @{
            Label = 'Settings'
            Hotkey = 's'
            Form = $settings
        }
        New-ConsoleMenuItem @menuItemOptions
        New-ConsoleMenuItem -Exit
    }
}
$menu = New-ConsoleMenu @menuOptions2
$menuOptions = @{
    Menu = $menu
    Layout = 'Shell'
}
Show-ConsoleMenu @menuOptions

Offer a preset for a menu form

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 New-ConsoleMenu in a complete example. Each lookup returns the script's source. Use the same slug with Show-ConsoleDemo to run it.

Parameters

-Content ScriptBlock optionalposition: 1
A scriptblock whose New-ConsoleMenuItem output becomes the items (and New-ConsoleMenu -Preset output the built-in presets).
-Description String optional
A sentence shown above the items.
-InputObject PSObject optionalpipeline: True (ByValue)
Menu items or preset records from the pipeline.
-Layout MenuLayout optional
The default layout for Show-ConsoleMenu: Auto, Classic, Shell or Inline.
Possible values: Auto, Classic, Shell, Inline
-Preset Object[] optional
Presets the app comes with (New-ConsoleMenu -Preset), listed before the saved ones by a -Presets item.
-Subtitle String optional
Muted text at the right of the footer (a version, an environment).
-Title String requiredposition: 0
The title (the app name for the top menu).

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.