New-ConsoleForm
Creates a form or wizard from fields (New-ConsoleField) for Read-ConsoleForm or a menu item.
Syntax
New-ConsoleForm
[-Command <String>]
[-CommandStyle <PowerShell| Posix| Windows>]
[[-Content] <ScriptBlock>]
[-Description <String>]
[-InputObject <PSObject>]
[-NoReview]
[-PageDescriptions <IDictionary>]
[-Preset <Object[]>]
[-StorageKey <String>]
[-SubmitText <String>]
[-Title] <String>
[<CommonParameters>]#All Parameter SetsDescription
The scriptblock's New-ConsoleField output becomes the fields. Fields with -Page are grouped into pages in the order the page names first appear, which turns the form into a wizard with a progress strip. Use -PageDescriptions to give each page its own sentence under the title. Unless -NoReview is given, a review page follows: every answer, the equivalent command line (from -Command and each field's -Parameter), Run, Copy command, Save preset and Back. Presets the form comes with (New-ConsoleForm -Preset, in the scriptblock or -Preset) are listed before the saved ones.
Examples
Example 1
function New-SharePlan {
param([string]$Name, [string]$Path, [switch]$ReadOnly)
[pscustomobject]@{ Name = $Name; Path = $Path; ReadOnly = [bool]$ReadOnly }
}
$formOptions = @{
Title = 'Share plan'
Command = 'New-SharePlan'
PageDescriptions = @{ Basics = 'Name and location of the share.'; Access = 'How people can use the share.' }
Content = {
$fieldOptions3 = @{
Required = $true
Key = 'Name'
Label = 'Share name'
Page = 'Basics'
ParameterName = 'Name'
}
New-ConsoleField @fieldOptions3
$fieldOptions2 = @{
MustExist = $true
Key = 'Path'
Label = 'Folder'
Kind = 'Path'
PathKind = 'Folder'
Page = 'Basics'
ParameterName = 'Path'
}
New-ConsoleField @fieldOptions2
$fieldOptions = @{
Key = 'ReadOnly'
Label = 'Read only'
Kind = 'Toggle'
Page = 'Access'
ParameterName = 'ReadOnly'
}
New-ConsoleField @fieldOptions
}
}
$form = New-ConsoleForm @formOptionsA two-page wizard
Example 2
function New-SharePlan {
param([string]$Name, [string]$Path, [switch]$ReadOnly)
[pscustomobject]@{ Name = $Name; Path = $Path; ReadOnly = [bool]$ReadOnly }
}
$formOptions = @{
Title = 'Share plan'
Command = 'New-SharePlan'
Content = {
$fieldOptions2 = @{
Required = $true
Key = 'Name'
Label = 'Share name'
ParameterName = 'Name'
}
New-ConsoleField @fieldOptions2
$fieldOptions = @{
Key = 'ReadOnly'
Label = 'Read only'
Kind = 'Toggle'
ParameterName = 'ReadOnly'
}
New-ConsoleField @fieldOptions
[pscustomobject]@{ Name = 'Archive'; Values = @{ Name = 'Archive'; ReadOnly = $true }; Description = 'A read-only archive share.' }
}
}
$form = New-ConsoleForm @formOptionsA form that comes with a preset
Example 3
Get-ConsoleDemo -Slug 'setup' | Select-Object -ExpandProperty Source
Get-ConsoleDemo -Slug 'toolbox' | Select-Object -ExpandProperty SourceRead any of these gallery scripts to see New-ConsoleForm in a complete example. Each lookup returns the script's source. Use the same slug with Show-ConsoleDemo to run it.
Parameters
- -Command String
- The command the equivalent command line starts with.
- -CommandStyle CommandStyle
- How the equivalent command line is written: PowerShell (-Name value), Posix (--name value) or Windows (/name:value).
- Possible values:
PowerShell,Posix,Windows - -Content ScriptBlock
- A scriptblock whose New-ConsoleField output becomes the fields.
- -Description String
- A sentence under the title.
- -InputObject PSObject
- Fields or preset records from the pipeline.
- -NoReview SwitchParameter
- Leaves out the review page.
- -PageDescriptions IDictionary
- Descriptions by page name, for pages declared by the fields. Pages without a matching entry keep their default description.
- -Preset Object[]
- Presets the form comes with (New-ConsoleForm -Preset), listed before the saved ones; presets emitted in the scriptblock are added too.
- -StorageKey String
- The key presets and remembered choices are stored under (default: the title).
- -SubmitText String
- The caption of the submit button (default Run).
- -Title String
- Heading displayed above the form's fields and navigation controls.
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.