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?
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)