Removing a self-signed certificate from my store

Is there a way to remove / remove a self-signed certificate from my store using powershell?

I tried

Remove-Item cert:\LocalMachine\My\$thumb 

this did not work, I got an exception: "The provider does not support this operation"

I also tried

  certmgr.msc /del /n "MyTestServer" /s MY 

he didn't work either

How to remove a certificate from the store?

Thanks in advance Jeez

+6
source share
6 answers

Remove-Item does not work with certificates because der cert-provider is only in powershell. Found information here

 $store = new-object system.security.cryptography.x509certificates.x509Store 'My','CurrentUser' $store.Open('ReadWrite') $certs = @(dir cert:\currentuser\my | ? { $_.Subject -like '*MyTestServer*' }) foreach ($cert in $certs) {$store.Remove($cert)} $store.close() 

I found a solution here in the comments. Therefore, it is not verified.

+7
source

Found this article because remove-item did not work.

This is not entirely true power, but I use this method:

 certutil -delstore my "5314bdfa0255be36e53e749d033" 

You can get the fingerprint using cert: \ LocalMachine \ my or through certutil. In my case, I have several certificates with the same name, so I like the method above because it gives me a specific purpose when I delete the certificate.

+5
source

This will work in powershell.

To get thumbpeint dir cert: \ localmachine \ my

To remove the fingerprint del cert: \ localmachine \ my \ thumbprint

+1
source

With PS 3.0, there is a more concise and idiomatic approach:

Remove-Item -Path cert:\LocalMachine\My\{Thumbprint} -DeleteKey

See TechNet for more .

+1
source

With PS 3.0, if you want to remove by subjectName

 Get-ChildItem -Path Cert:\CurrentUser\My | where { $_.subject -eq "CN=MysubjectName" } | Remove-Item 
0
source

I understand that this is an old branch, but since I look at the same thing, now I decided to write. I need to remove certificates from all stores by friendly name.

Understand that this is not an answer for the OP, but may help someone.

If required by someone, this works for me dir cert: -Recurse | Where-Object { $_.FriendlyName -like "*SOMENAME*" } | Remove-Item dir cert: -Recurse | Where-Object { $_.FriendlyName -like "*SOMENAME*" } | Remove-Item

0
source

Source: https://habr.com/ru/post/886118/


All Articles