Cmdlet
Read-ConsoleNumber
Asks for a number.
Syntax
Read-ConsoleNumber
[-Culture <CultureInfo>]
[-Default <Decimal>]
[-Description <String>]
[-Integer]
[-Maximum <Decimal>]
[-Minimum <Decimal>]
[-Mode <Rich| Line| Accessible| Snapshot>]
[-ParameterName <String>]
[-Step <Decimal>]
[[-Title] <String>]
[-Validator <ScriptBlock>]
[<CommonParameters>]#Parameter set:
All Parameter SetsDescription
Whole numbers with -Integer (returns [int]), decimals otherwise (returns [decimal]). -Minimum and -Maximum are shown as a hint and checked; Up and Down step by -Step (PgUp and PgDn by ten steps).
Examples
Example 1
$numberOptions = @{
Integer = $true
Title = 'Port'
Minimum = 1
Maximum = 65535
Default = 443
}
$port = Read-ConsoleNumber @numberOptionsA port number
Example 2
$numberOptions = @{
Title = 'Servers per batch'
Default = 5
Minimum = 1
Maximum = 20
}
$count = Read-ConsoleNumber @numberOptions
$textOptions = @{
Text = @("Batch size: $count")
}
Write-ConsoleText @textOptionsChoose a bounded batch size
Example 3
Get-ConsoleDemo -Slug 'prompt-tour' | Select-Object -ExpandProperty SourceRead the gallery script to see Read-ConsoleNumber in a complete example. Each lookup returns the script's source. Use the same slug with Show-ConsoleDemo to run it.
Parameters
- -Culture CultureInfo
- Culture used to parse and display the answer; omitted uses the current culture.
- -Default Decimal
- The numeric answer initially selected when the question opens.
- -Description String
- Help text under the question.
- -Integer SwitchParameter
- Accepts whole numbers only and returns [int].
- -Maximum Decimal
- Upper bound accepted by the numeric editor, inclusive.
- -Minimum Decimal
- Lower bound accepted by the numeric editor, inclusive.
- -Mode InteractionMode
- Forces how to ask: Rich (in-place prompt), Line (question and typed answer), Accessible (numbered, no redraws) or None (use the default or fail).
- Possible values:
Rich,Line,Accessible,Snapshot - -ParameterName String
- The parameter of your script that supplies this value without a prompt (named in the non-interactive error, for example -Domain).
- -Step Decimal
- The step of Up and Down (default 1).
- -Title String
- The prompt displayed above the input control.
- -Validator ScriptBlock
- A validator: $_ is the number; return $true, $false or an error message.
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.