从我的商店中删除自签名证书

问题描述 投票:6回答:5

有没有办法使用PowerShell从我的商店中删除/卸载自签名证书?

我试过了

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

它不起作用,我得到一个例外说“提供商不支持此操作”

我也试过了

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

它也没用

如何从商店中卸载证书?

在此先感谢Jeez

ssl powershell
5个回答
7
投票

Remove-Item不适用于证书,因为在certhell中只提供了cert-provider。发现信息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() 

我在评论中找到了解决方案here。所以它没有经过测试。


5
投票

发现这篇文章是因为remove-item无法正常工作。

这不是'true'的powershell,但我使用这种方法:

certutil -delstore my "5314bdfa0255be36e53e749d033"

您可以通过cert:\ LocalMachine \ my或通过certutil获取指纹。在我的情况下,我有多个具有完全相同名称的证书,所以我更喜欢上面的方法,因为它在我删除证书时给了我一个特定的目标。


1
投票

这在powershell中也可以使用

获取指纹目录证书:\ localmachine \ my

要删除指纹del cert:\ localmachine \ my \ thumbprint


1
投票

使用PS 3.0,有一种更简洁和惯用的方法:

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

有关所有细节,请参阅TechNet


0
投票

使用PS 3.0,如果要删除subjectName

Get-ChildItem -Path Cert:\CurrentUser\My | where { $_.subject -eq "CN=MysubjectName" } | Remove-Item
© www.soinside.com 2019 - 2024. All rights reserved.