Prompting for Passwords

by Sep 22, 2010

If you need to prompt for a secret password and do not want it to be visible while entered, you should use Get-Credential. This cmdlet returns a credential object, which contains the entered password in encrypted format. You should then call GetNetworkCredential() to un-encrypt it to plain text:

$cred = Get-Credential SomeUserName
$cred.Password
System.Security.SecureString
$cred.GetNetworkCredential()
UserName Password Domain
——– ——– ——
SomeUserName secret
$cred.GetNetworkCredential().Password
secret

Twitter This Tip! ReTweet this Tip!