If you want to save credentials in a file and later want to use it in a script here is the trick. You can use PowerShell's built-in XML serialization (Clixml): #1. Get The Credentials $cred = Get-Credentails #2. Save the Credentails as a file $cred | Export-CliXml "MyFileName.xml" #3. Read the Credentials back from file $myCred = Import-CliXml "<Path>/MyFileName.xml"