The following PowerShell cmdlet will prompt you for a password as input. The input will be encrypted and saved to the root of C in a file called password.pass.
read-host -assecurestring | convertfrom-securestring | out-file C:password.pass
To read the encrypted password and create a credentials object using the following.
$pwd = get-content C:temppassword.pass | convertto-securestring
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist “domainaccount”,$pwd
The $cred object can be password cmdlets which require username/password information.