Skip to content
ConsoleMonster
Cmdlet

Read-ConsoleNumber

Module
ConsoleMonster
Outputs
System.Int32 System.Decimal

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 Sets

Description

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 @numberOptions

A 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 @textOptions

Choose a bounded batch size

Example 3

Get-ConsoleDemo -Slug 'prompt-tour' | Select-Object -ExpandProperty Source

Read 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 optional
Culture used to parse and display the answer; omitted uses the current culture.
-Default Decimal optional
The numeric answer initially selected when the question opens.
-Description String optional
Help text under the question.
-Integer SwitchParameter optional
Accepts whole numbers only and returns [int].
-Maximum Decimal optional
Upper bound accepted by the numeric editor, inclusive.
-Minimum Decimal optional
Lower bound accepted by the numeric editor, inclusive.
-Mode InteractionMode optional
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 optional
The parameter of your script that supplies this value without a prompt (named in the non-interactive error, for example -Domain).
-Step Decimal optional
The step of Up and Down (default 1).
-Title String optionalposition: 0
The prompt displayed above the input control.
-Validator ScriptBlock optional
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.