PowerShell Scripts, Tips, Expert Advices, Forums, and Resources

Geek Sync Live

Welcome to PowerShell.com, the educational and community site for Windows PowerShell People. Get a quick overview.

As a Powershell.com member you will have access to:

  • Daily PowerShell tips written by Microsoft MVPs and other leading Windows PowerShell experts
  • Free Windows PowerShell advice and training provided by Microsoft MVPs and other leading Windows PowerShell experts
  • Access to leading Windows PowerShell blogs
  • A free ebook, Mastering PowerShell, written by Microsoft MVP Dr. Tobias Weltner
PowerTip of the Day

Exporting and Importing Credentials

It is trivial to save credentials to disk so you can later re-import them. This is the part that takes a credential and saves it to disk:

#requires -Version 3

$path = "$home\Desktop\cred.xml"
$cred = Get-Credential
$cred | Export-Clixml -Path $path

And this is the part that imports it back in whenever it suits you:

$path = "$home\Desktop\cred.xml"
$cred = Import-Clixml -Path $path

You can then use the credential in $cred wherever a cmdlet requires the -Credential parameter.

Note that the credential is stored in encrypted format. It can be imported only from the very same person on the very same machine.

Twitter This Tip! ReTweet this Tip!

Copyright 2012 PowerShell.com. All rights reserved.