Retrieving Clear Text Password

by Jul 20, 2010

Get-Credential is a great way of prompting for credentials, but the Password you enter into the dialog will be encrypted. Sometimes, you may need a clear text password. Here is one way to restore the clear text password entered into the dialog:

$cred = Get-Credential
$pwd = [Runtime.InteropServices.Marshal]::PtrToStringAuto( [Runtime.InteropServices.Marshal]::SecureStringToBSTR( $cred.Password ))
"Password: $pwd"

Twitter This Tip! ReTweet this Tip!