locked
cmdkey syntax RRS feed

  • Question

  • Hi guys,

    glad to write my second post here on technet.

    I am having issues with cmdkey utility syntax. I am trying to prepare a script, either powershell or cmd  that will completely wipe out all credentials stored for a single user, But I got stuck before putting altogether in the script.

    Basically cmdkey /delete:targetname works fine with most of the credentials store, but there are a couple of cases where, whatever I do I cannot make it work. These are:

    Target: LegacyGeneric:target=OneDrive Cached Credential Business - Business1
    Type: Generic
    User: 3e47136a-2382-43d3-98e7-fa3646a91bfe
    Local machine persistence


    Target: LegacyGeneric:target=Microsoft_OC1:uri=airoldia1@danieli.it:certificate:OCS:1
    Type: Generic Certificate
    User: <Certificate>

    First one is the most difficult since it has spaces in btw.

    So I started to test the single command to delete such credentials, Few things I tried:

    cmdkey /delete:"LegacyGeneric:target=OneDrive Cached Credential Business - Business1"

    cmdkey /delete:'LegacyGeneric:target=OneDrive Cached Credential Business - Business1'

    Nothing seems to work for this particular case...The same syntax, without quotes, works perfectly with other TargetNames without spaces.

    Please advise...

    Thank you all in advance

    Tuesday, October 13, 2020 1:36 PM

All replies

  • I think the problem isn't the spaces, but the hyphen. Remove the hyphen from your target and you should get cmdkey to run, but return "*NONE*" as the result.

    Search for "cmdkey delete hyphen" (and other variations) and you'll find others with the same problem (none that I found with a successful resolution).

    You might try the Powershell module "CredentialManager". Or, try the CredMan.ps1 script in the Microsoft Script Gallery.


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Tuesday, October 13, 2020 9:27 PM
  • Yes, that's what I thought could be a possible issue. Just wanted to use an utility that was integrated in the OS rather than using other PS additional modules that I have to install. 

    Thanks for reply though, appreciate.

    Wednesday, October 14, 2020 7:27 AM
  • While I didn't find anyone that had an answer to using cmdkey whith a hypen, I did find other code that used .Net directly to do the work. Check some of the search results for posts on Stack Overflow.

    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Wednesday, October 14, 2020 2:43 PM
  • Sorry for late reply Rich, thanks for your tip.
    Monday, November 2, 2020 8:27 AM