Skip to content
ConsoleMonster
Cmdlet

Read-ConsoleForm

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

Shows a form or wizard and returns the answers.

Syntax

Read-ConsoleForm
[-AppName <String>]
[-AsPlainText]
[[-Form] <PSObject>]
[-Inline]
[-Mode <Rich|Line|Accessible|Snapshot>]
[-PassThru]
[-Preset <String>]
[-RememberLastChoices]
[-StorageRoot <String>]
[<CommonParameters>]
#
Parameter set: All Parameter Sets

Description

The form opens on the alternate screen (or in the scrollback with -Inline). Fields are edited in place; choice fields open a filterable list; dependent options load with a spinner. The review page shows every answer and the equivalent command (copy it, save the answers as a named preset, or run). The answers come back as one object with a property per visible field (secrets as SecureString unless -AsPlainText); -PassThru returns the full result (Submitted, Values, CommandLine) instead. Cancelling returns nothing. -AppName stores presets, and with -RememberLastChoices the last answers, per user under %APPDATA%\ConsoleMonster\<app>. In remoting and the ISE the fields are asked one by one; without a user the defaults are used, or an error names the first field that needs a value.

Examples

Example 1

$formOptions2 = @{
    Title = 'Example'
    Content = {
        $fieldOptions = @{
            Key = 'Name'
            Label = 'Name'
            Default = 'example'
        }
        New-ConsoleField @fieldOptions
    }
}
$form = New-ConsoleForm @formOptions2
$formOptions = @{
    Form = $form
}
$answers = Read-ConsoleForm @formOptions
if ($answers) { Write-Host "Selected $($answers.Name)" }

Run a wizard and use the answers

Example 2

$formOptions2 = @{
    Title = 'Inspect inventory'
    Content = {
        $fieldOptions = @{
            Required = $true
            Key = 'Server'
            Label = 'Server name'
            Default = 'web01'
        }
        New-ConsoleField @fieldOptions
    }
}
$form = New-ConsoleForm @formOptions2
$formOptions = @{
    Form = $form
}
Read-ConsoleForm @formOptions | Show-ConsoleTable

Collect a server name and display the submitted values

Example 3

Get-ConsoleDemo -Slug 'setup' | Select-Object -ExpandProperty Source

Read the gallery script to see Read-ConsoleForm 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.
-AsPlainText SwitchParameter optional
Returns secrets as plain strings.
-Form PSObject optionalposition: 0pipeline: True (ByValue)
The form from New-ConsoleForm.
-Inline SwitchParameter optional
Draws the form in the scrollback instead of the alternate screen.
-Mode InteractionMode optional
Forces how to ask: Rich, Line, Accessible or None.
Possible values: Rich, Line, Accessible, Snapshot
-PassThru SwitchParameter optional
Returns the full result (Submitted, Values, CommandLine) instead of the answers.
-Preset String optional
A preset to apply first: a built-in one (New-ConsoleForm -Preset) or one saved under -AppName.
-RememberLastChoices SwitchParameter optional
Remembers the submitted answers and offers them next time (needs -AppName).
-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.