提问人:Sarath G 提问时间:11/15/2023 最后编辑:litSarath G 更新时间:11/15/2023 访问量:25
如何使用 PowerShell 脚本删除与 LocalMachine 存储中的证书关联的私钥?
How to delete a Private key associated with a certificate in LocalMachine store using PowerShell script?
问:
我想使用 Powershell 脚本删除与 LocalMachine\Root 中的证书关联的私钥。我需要首先使用其友好名称从商店中查找此证书,因为我们没有指纹。
我使用了 ,但它仅从 LocalMachine\Root 中删除证书,但私钥仍存在于 Personal 文件夹中。Remove-Item -DeleteKey
在搜索了许多论坛后,我找不到任何直接的答案。任何帮助都是值得赞赏的。
Powershell 版本 - 5.1,操作系统 - Windows 10
我尝试了以下代码,它只删除了根证书,而不是私钥。
$certFriendlyName = 'MyTestCertificate'
Set-Location Cert:\LocalMachine\Root
$cert = Get-ChildItem | Where-Object {$_.FriendlyName -match $certFriendlyName}
$cert
$cert | Remove-Item -DeleteKey
如果我不Set-Location,“-DeleteKey”开关不起作用并引发错误
A parameter cannot be found that matches parameter name 'DeleteKey'
答: 暂无答案
评论
$cert.HasPrivateKey
$cert.HasPrivateKey