Skip to content
ConsoleMonster
Cmdlet

Read-ConsoleConfirm

Module
ConsoleMonster
Outputs
System.Boolean

Asks a yes/no question and returns $true or $false.

Syntax

Read-ConsoleConfirm
[-Default <Boolean>]
[-Description <String>]
[-Destructive]
[-Mode <Rich|Line|Accessible|Snapshot>]
[-NoText <String>]
[-ParameterName <String>]
[[-Title] <String>]
[-TypedConfirmation <String>]
[-Warning <String>]
[-YesText <String>]
[<CommonParameters>]
#
Parameter set: All Parameter Sets

Description

Shows the question with the answers inline (the default focused); Y and N answer at once, arrows move, Enter takes the focused answer and Esc answers no. With -TypedConfirmation the user must type a text (a server name, a domain) before a destructive action; Esc then returns $false. In remoting and the ISE the host asks (PromptForChoice); without a user the default is returned.

Examples

Example 1

if (Read-ConsoleConfirm 'Inspect the current process?' -Default $false) { Get-Process -Id $PID }

A question with a default

Example 2

if (Read-ConsoleConfirm 'Remove 3 servers from the inventory?' -TypedConfirmation 'inventory' -Warning 'This cannot be undone.') { Write-Host 'Would remove servers from the inventory' }

A typed confirmation before deleting

Example 3

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

Read the gallery script to see Read-ConsoleConfirm in a complete example. Each lookup returns the script's source. Use the same slug with Show-ConsoleDemo to run it.

Parameters

-Default Boolean optional
The answer initially selected; pressing Enter accepts this value.
-Description String optional
Help text under the question.
-Destructive SwitchParameter optional
Marks the question as destructive (a warning mark; No is focused unless -Default says otherwise).
-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
-NoText String optional
The caption of the negative answer.
-ParameterName String optional
The parameter of your script that supplies this value without a prompt (named in the non-interactive error, for example -Domain).
-Title String optionalposition: 0
The prompt displayed above the input control.
-TypedConfirmation String optional
The text the user must type to confirm.
-Warning String optional
Warning shown for a typed confirmation. Overrides -Description as the warning text; without -Warning the existing description remains the warning.
-YesText String optional
The caption of the positive answer.

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.