Skip to content

Instantly share code, notes, and snippets.

@altrive
Created March 25, 2014 15:29
Show Gist options
  • Save altrive/9764229 to your computer and use it in GitHub Desktop.
Save altrive/9764229 to your computer and use it in GitHub Desktop.

Add CredentialManager support

It's seems many people creating their own credential management solution.

It's seems, solutions classified 2 types of approach. and there are pros/cons respectively.

  1. Use OS native Windows Credential Manager(by P/Invoke).
  2. Persist encrypted credential to file(JSON/XML) under $profile directory.

Please add standard credential management support to PowerShell.

#Example:
#Set credential to CredentialManager(password is encrypted by DPAPI)
Set-Credential -Id "Admin" -UserName "domain/Administrator" -Password "[Password]" -Persist

#Get credential from CredentialManager
$cred = Get-Credential -Id "Admin"

Also, it may be useful, existing cmdlets -Credential parameter accept string, and automatically resolved to credential by using CredentialManager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment