7

I am trying to add and retrieve credentials from Windows Credential Manager using a command prompt.

To add a new credential, I have the command like below and it works perfectly:

cmdkey /add:testTarget /user:testUser /pass:testPassword

However, when I try to retrieve the credentials, which I have added earlier (testTraget) using CMD, I am unable to get the password using the command below:

cmdkey /list:testTarget

The command only returns the Target(testTarget),Type(Domain Password), and the Username(testUser)

How can I retrieve the testUser password?

I know this is possible in Mac OS using Bash and keychain.

Benjamin
  • 3,499
  • 8
  • 44
  • 77

2 Answers2

2

"How can I retrieve the testUser password?"

This is not possible using cmdkey.

Reference cmdkey:

Create, list or delete stored user names, passwords or credentials.

...

Once stored, passwords are not displayed.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
DavidPostill
  • 7,734
  • 9
  • 41
  • 60
2

It's possible to work with passwords from cmdkey's credentialstore using powershell and the Credman.ps1 library.

https://gallery.technet.microsoft.com/scriptcenter/PowerShell-Credentials-d44c3cde

Add credentials as system user (after a psexec -s in administrator's powershell console). Run powershell script as system user as well (ie. in task scheduler tasks) for safe usage.

To learn more about Sysinternal's psExec and cmdkey see this answer: https://superuser.com/questions/1206443/how-to-add-cached-credentials-for-the-windows-system-acount

--

Adding a password

cmdkey /generic:Foo /user:bar /pass:banana

Retrieving plain-text password with powershell

. "Credman.ps1"

$CredKey = "Foo"

$sourceCredential = Read-Creds $CredKey
$pass = $sourceCredential.CredentialBlob.tostring()
write-host $pass
Michael D.
  • 1,795
  • 2
  • 18
  • 25