Skip to content
ConsoleMonster
Cmdlet

Read-ConsoleSecret

Module ConsoleMonster
Inputs
None
Outputs
System.Security.SecureString System.String

Asks for a secret and returns a SecureString (or a string with -AsPlainText).

Syntax

Read-ConsoleSecret [-AllowEmpty] [-AsPlainText] [-Description <String>] [-Hidden] [-MinLength <Int32>] [-Mode <Rich|Line|Accessible>] [-ParameterName <String>] [-Title] <String> [-Validate <ScriptBlock>] [<CommonParameters>]
#
Parameter set: All Parameter Sets

Description

Asks for a secret and returns a SecureString (or a string with -AsPlainText).

The typed text is masked (or not shown at all with -Hidden); Ctrl+R reveals it while held open. The answer never appears in the scrollback summary. In remoting and the ISE the host reads it (ReadLineAsSecureString).

Examples

Authored help example

EXAMPLE 1

Read-ConsoleSecret -Title 'Value'

Parameters

-AllowEmpty SwitchParameter optional
Accepts an empty answer.
-AsPlainText SwitchParameter optional
Returns a plain string instead of a SecureString.
-Description String optional
Help text under the question.
-Hidden SwitchParameter optional
Shows nothing while typing (not even the length).
-MinLength Int32 optional
The fewest characters.
-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
-ParameterName String optionalaliases: Parameter
The parameter of your script that supplies this value without a prompt (named in the non-interactive error, for example -Domain).
-Title String requiredposition: 0aliases: Prompt, Question
The question.
-Validate ScriptBlock optional
A validator: $_ is the secret; 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.