Search code examples
gitpowershellgithubcredentials

How to add Windows Credentials via Powershell?


I am trying to add Windows Credentials for my Github account via powershell.

I type in the below command into powershell:

cmdkey /add:"git:https://github.com" /user:"myusername" /pass:"myauthtoken"

It returns error CMDKEY: The parameter is incorrect.

How can I fix this?

Note that the above parameter values work when I add credentials via gui with Control Panel -> Credential Manager -> Add a Generic Credential.


Solution

  • From the output of cmdkey /?:

    To create generic credentials:
       The /add switch may be replaced by /generic to create generic credentials
    

    If I take a look at the generic github credentials in my vault, their target name is listed as:

    Target: LegacyGeneric:target=git:https://github.com
    

    So, I'd suggest trying the following:

    cmdkey /generic:LegacyGeneric:target=git:https://github.com /user:"myusername" /pass:"myauthtoken"