Prompting for Secret Passwords via Console with Powershell

by Sep 23, 2010

You can use Read-Host to hide user inputs for safe password prompts:

$pwd = Read-Host -AsSecureString 'Enter Password'
Enter Password: ******
$pwd
System.Security.SecureString

However, the result in this case is an encrypted secure string. To un-encrypt it to plain text, you can easily convert the password into a credential object and use its GetNetworkCredential() method:

(New-Object System.Management.Automation.PSCredential('dummy',$pwd)).GetNetworkCredential().Password
secret

Twitter This Tip! ReTweet this Tip!