Skip to content
ConsoleMonster
Cmdlet

New-ConsoleCommand

Module
ConsoleMonster
Inputs
None
Outputs
ConsoleMonster.Interactive.AppCommand

Defines an in-app action for buttons, palettes and grid rows.

Syntax

New-ConsoleCommand
[-ArgumentList <Object[]>]
[-ConfirmPrompt <String>]
[-ImportModule <String[]>]
[-Key] <String>
[-Label <String>]
-ScriptBlock <ScriptBlock>
[-Shortcut <String>]
[<CommonParameters>]
#
Parameter set: All Parameter Sets

Description

Creates a passive command definition. Work runs in an isolated runspace with explicit arguments and module imports, not the defining closure. The first script parameter receives a deserialized row snapshot. Selected or marked rows are captured before optional modal confirmation and run in order. Output, host messages, warnings, errors and progress stream into the app's log. F6 requests cancellation while the app stays open. After a two-second grace period the app becomes available even when a native call is still stopping. That command cannot start again until its previous runspace exits; other commands remain available. Cancellation cannot undo effects already performed by an external operation.

Examples

Example 1

$restart = New-ConsoleCommand -Key Restart -Label 'Restart service' -Shortcut Ctrl+R -ConfirmPrompt 'Restart selected services?' -ScriptBlock { param($Row) Restart-Service -Name $Row.Name -ErrorAction Stop }; Get-Service | Show-ConsoleGrid -Action $restart

Restart selected services after confirmation without closing the viewer.

Parameters

-ArgumentList Object[] optional
Explicit values serialized when defining the command and passed after Row.
-ConfirmPrompt String optional
Optional modal confirmation text. {Selection} expands to the focused row label or marked-row count. No is the initial answer.
-ImportModule String[] optional
Modules to import in the operation's isolated runspace.
-Key String requiredposition: 0
Stable command identity.
-Label String optional
Visible command text; defaults to Key.
-ScriptBlock ScriptBlock required
Operation source, receiving param($Row, ...explicit arguments). Closure variables are not inherited.
-Shortcut String optional
Optional key chord, for example Ctrl+R or F5.

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.