I´m looking for a way to hide the user input from the Read-Host cmdlet.
I know I can do this with -assecurestring, but I´d like to save the input as plain text in my variable.
Is there a possible way to do this?
The Read-Host cmdlet reads a line of input from the console (stdin). You can use it to prompt a user for input. Because you can save the input as a secure string, you can use this cmdlet to prompt users for secure data, such as passwords. Read-Host has a limit of 1022 characters it can accept as input from a user.
In PowerShell, the input can be retrieved from the user by prompting them with Read-Host Cmdlet. It acts as stdin and reads the input supplied by the user from the console. Since the input can also be stored as secured string, passwords can also be prompted using this cmdlet.
Contains an enumerator that enumerates all input that is passed to a function. The $input variable is available only to functions and script blocks (which are unnamed functions). In the Process block of a function, the $input variable enumerates the object that is currently in the pipeline.
Getting the Prompt function To get the Prompt function, use the Get-Command cmdlet or use the Get-Item cmdlet in the Function drive. To get the script that sets the value of the prompt, use the dot method to get the ScriptBlock property of the Prompt function.
You have to use the -AsSecureString
switch but you can also retrieve the plaintext value:
$securedValue = Read-Host -AsSecureString
$bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($securedValue)
$value = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With