Let’s assume you would like to open multiple PowerShell consoles running under different identities – or launch whatever application you require, just as someone else.
To do that, you would have to log on as someone else, and obviously that’s a strain. So here is a way to save credentials to file in a safe way: the password is encrypted using your identity and your machine as a secret. You can get it back only if you are the person that saved them, and if you do it on the machine where you saved the file:
# saving credential securely to file Get-Credential | Export-Clixml -Path "$home\login.xml"
The credential is saved to your user profile. Change the path if you’d prefer another place, and add more calls if you need to save more credentials to other files – as many as you need.
Next, let’s see how you load a saved credential, and then launch an application with that identity:
# getting back saved credential $cred = Import-Clixml -Path "$home\login.xml" # launch application Start-Process -FilePath powershell -Credential $cred -Work c:\ -LoadUserProfile
This would launch a new PowerShell as the user that you specified originally – no need to log on manually.