Is it possible to hide the user input from read-host in Powershell?

19,740

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)
Share:
19,740
Admin
Author by

Admin

Updated on June 05, 2022

Comments

  • Admin
    Admin almost 2 years

    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?