Cmdlet
Read-ConsoleSecret
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 SetsDescription
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
EXAMPLE 1
Read-ConsoleSecret -Title 'Value'Parameters
- -AllowEmpty SwitchParameter
- Accepts an empty answer.
- -AsPlainText SwitchParameter
- Returns a plain string instead of a SecureString.
- -Description String
- Help text under the question.
- Shows nothing while typing (not even the length).
- -MinLength Int32
- The fewest characters.
- -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 - -ParameterName String
- The parameter of your script that supplies this value without a prompt (named in the non-interactive error, for example -Domain).
- -Title String
- The question.
- -Validate ScriptBlock
- 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.