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.
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
"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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With