Saving Multiple Credentials

by Jun 29, 2016

Thanks to Jaap Brasser’s finding, here is an easy way of encrypting a bunch of credentials:

$CredPath = "$home\Desktop\mycreds.xml"
$creds = @{
  Local = Get-Credential -Message LocalAccount
  Remote = Get-Credential -Message RemoteAccount
  Domain = Get-Credential -Message DomainAccount
}

$creds | Export-Clixml -Path $OutPath

To read in these credentials, use this:

$CredPath = "$home\Desktop\mycreds.xml"
$creds = Import-Clixml -Path $CredPath 

$creds.Local
$creds.Remote
$creds.Domain

# example
Get-WmiObject -Class Win32_BIOS -ComputerName server1 -Credential $creds.Remote

Note that the passwords are safely encrypted with your identity and the machine identity, so you can read in the credentials only on the machine where they were generated, and only if you are the same person that saved them.

Twitter This Tip! ReTweet this Tip!