Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PowerShell: Delete all cmdkey credentials #PowerShell #Windows
cmdkey /list | ForEach-Object{if($_ -like "*Ziel:*"){cmdkey /del:($_ -replace " ","" -replace "Ziel:","")}}
@JohnRanger

This comment has been minimized.

Copy link

@JohnRanger JohnRanger commented May 6, 2014

And here the english Version:

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

@ramassin

This comment has been minimized.

Copy link

@ramassin ramassin commented Mar 3, 2015

cmdkey /list | ForEach-Object{if($_ -like "*Destinazione:*"){cmdkey /del:($_ -replace " ","" -replace  Destinazione:","")}}
@CermakPOI

This comment has been minimized.

Copy link

@CermakPOI CermakPOI commented Mar 5, 2015

In the english version the * are missing for the "-like":
cmdkey /list | ForEach-Object{if($_ -like "Target:"){cmdkey /delete:($_ -replace " ","" -replace "Target:","")}}

@HerrHeuschrecke

This comment has been minimized.

Copy link

@HerrHeuschrecke HerrHeuschrecke commented Sep 10, 2016

Danke/grazie/thanks/děkuji! This line I needed this late night.

And yes, Cermak, those "*" were important. :)
So, correct English line:
cmdkey /list | ForEach-Object{if($_ -like "*Target:*"){cmdkey /del:($_ -replace " ","" -replace "Target:","")}}

@jcmmarq

This comment has been minimized.

Copy link

@jcmmarq jcmmarq commented May 1, 2017

works great. However what if you want to delete just specific Items that starts with a specific name for example I wasn't ot delete All credentials that the Target Name starts with Microsoft_OC1. I have tried using the above command with the following but does not work
cmdkey /list | ForEach-Object{if($_ -like "Target:Microsoft_OC1"){cmdkey /del:($_ -replace " ","" -replace "Target:","")}}
the object here is to only delete specific credentials not all of them.

Here is a credential that is currently stored.
Users\marquesj.AUTOCLUB> cmdkey /list

Currently stored credentials:

Target: LegacyGeneric:target=Microsoft_OC1:uri=marquesj@aaa-calif.com:specific:

LOC:1
Type: Generic
User: marquesj

@jcmmarq

This comment has been minimized.

Copy link

@jcmmarq jcmmarq commented May 1, 2017

appreciate any help you can provide. Thanks!!!

@mrajusjp

This comment has been minimized.

Copy link

@mrajusjp mrajusjp commented Sep 18, 2017

Try this.
cmdkey /list | ForEach-Object{if($_ -like "*Microsoft_OC1*"){cmdkey /del:($_ -replace " ","" -replace "Target:","")}}

@cpratlong

This comment has been minimized.

Copy link

@cpratlong cpratlong commented Oct 15, 2018

Here is a "filtering" allowing to erase all, whatever windows language it is

$Credentials = (cmdkey /list | Where-Object {$_ -like "*Target=*"})
Foreach ($Target in $Credentials) {
    $Target = ($Target -split (":", 2) | Select-Object -Skip 1).substring(1)
    $Argument = "/delete:" + $Target
    Start-Process Cmdkey -ArgumentList $Argument -NoNewWindow -RedirectStandardOutput $False
    }
@luiscarrillo1

This comment has been minimized.

Copy link

@luiscarrillo1 luiscarrillo1 commented Oct 25, 2018

Try this. Just tried it and it work! Used regex to remove everything the beginning of Target:....to after target=. Then pass that on to /del:$_

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

@luiscarrillo1

This comment has been minimized.

Copy link

@luiscarrillo1 luiscarrillo1 commented Oct 25, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.