Prompt for password without using Get-Credential or Read-Host -AsSecureString, but not display text entered on screen


  • I'm automating the creation of some scheduled tasks by calling schtasks. I need to supply a password for the /rp switch, but schtasks won't take System.Security.SecureString text. So Get-Credential is out, as is Read-Host -AsSecureString. I can use Read-Host, but I'm really looking for a way to obfuscate the display of the text entered.


    Friday, September 2, 2011 3:33 PM


  • You can convert a securestring to plain text:

    $password = Read-Host -assecurestring "Please enter your password"
    $password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))

    Friday, September 2, 2011 3:36 PM

All replies