Save PowerShell Credentials Permanently

I just found a post on geekswithblogs.net that shows how to store your password in a text file, then call it back as a secure credentials object. This is extremely useful for putting in your PowerShell profile if you use multiple passwords or admin multiple domains. Keep in mind where he has 'test' in his script, should be replaced with your desired account name.

Here's the code to store the credential:

read-host -assecurestring | convertfrom-securestring | out-file C:\securestring.txt

And here is the code to call it back and store it as a variable (this is where you replace the word 'test'). Change $mycred to whatever you want the credential variable to be.

$pass = cat C:\securestring.txt | convertto-securestring
$mycred = new-object -typename System.Management.Automation.PSCredential -argumentlist "test",$pass

Here is example useage if you left the credential as $mycred:

gwmi win32_computersystem -computer somecomputer -cred $mycred