Skip to content

Instantly share code, notes, and snippets.

@janikvonrotz
Created December 6, 2013 07:39
Show Gist options
  • Save janikvonrotz/7819990 to your computer and use it in GitHub Desktop.
Save janikvonrotz/7819990 to your computer and use it in GitHub Desktop.
PowerShell: Delete all cmdkey credentials #PowerShell #Windows
cmdkey /list | ForEach-Object{if($_ -like "*Ziel:*"){cmdkey /del:($_ -replace " ","" -replace "Ziel:","")}}
@BigKatGalarraga
Copy link

looks like the * asterisks were removed when posting. You can add them before/after the quotes to -like "Target:" or use -match "Target: "

@vinayiitkgp
Copy link

I need to delete cached credentials of a user. The tool I am using to connect to the remote computer runs under sys. So cmdkey /list is returning only the targets that it has access to. When the cmdkey /list is run on the target computer directly on the powershell console, it returns all the target that the logged user has access to. How do I retrieve these targets from a remote session running user sys?

@leblancmeneses
Copy link

Target: LegacyGeneric:target=Adobe App Prefetched Info (cc)(Part2)

cmdkey /list | ForEach-Object {
  if ($_ -like "*Adobe*") {
    cmdkey /del:($_ -replace '^[^=]+',"" -replace "=","")
  }
}

@undone37
Copy link

undone37 commented Feb 9, 2023

German:
cmdkey /list | ForEach-Object{if($_ -like "*Ziel:*"){cmdkey /del:($_ -replace "    ","" -replace "Ziel: ","")}}
English:
cmdkey /list | ForEach-Object{if($_ -like "*Target:*"){cmdkey /del:($_ -replace "    ","" -replace "Target: ","")}}

This will even delete entries with spaces (based on the original version).

@Joadison
Copy link

O comando é cmdkey /list | ForEach-Object {if($_ -like "Target=") {echo($_ -replace " ","" -replace "^.*target=","")}}

@Joadison
Copy link

O comondo correto é

cmdkey /list | ForEach-Object {if($_ -like "Target=") {echo($_ -replace " ","" -replace "^.*target=","")}}

@Joadison
Copy link

cmdkey /list | ForEach-Object {if($_ -like "*Target=*") {cmdkey /delete:($_ -replace " ","" -replace "^.*target=","")}}

@lucapiccio
Copy link

lucapiccio commented Mar 18, 2024

For me all your listing depends from windows language version.

If you want to delete all key ignoring the lang of windows you can do:

cmdkey /list | ForEach-Object{
    if($_ -like "*=*"){
        $c = ($_ -replace (' ')).split(":", 2)[1]
        cmdkey.exe /delete $c | Out-Null
    }
}

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