Read-ConsoleForm
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>]#All Parameter SetsDescription
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-ConsoleTableCollect a server name and display the submitted values
Example 3
Get-ConsoleDemo -Slug 'setup' | Select-Object -ExpandProperty SourceRead 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
- The app name presets and remembered choices are stored under.
- -AsPlainText SwitchParameter
- Returns secrets as plain strings.
- -Form PSObject
- The form from New-ConsoleForm.
- -Inline SwitchParameter
- Draws the form in the scrollback instead of the alternate screen.
- -Mode InteractionMode
- Forces how to ask: Rich, Line, Accessible or None.
- Possible values:
Rich,Line,Accessible,Snapshot - -PassThru SwitchParameter
- Returns the full result (Submitted, Values, CommandLine) instead of the answers.
- -Preset String
- A preset to apply first: a built-in one (New-ConsoleForm -Preset) or one saved under -AppName.
- -RememberLastChoices SwitchParameter
- Remembers the submitted answers and offers them next time (needs -AppName).
- -StorageRoot String
- 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.