如何删除具有特定模板的证书?
问题描述:
我在Windows上有一些证书。这些证书有不同的模板。如何删除具有特定模板的证书?
我可以得到指纹:
$Certificates = get-childitem cert:\LocalMachine\My
我可以得到模板:
$Template = ($Certificates.extensions | where-object{$_.oid.FriendlyName -match "Certificate Template Information"}).format(0)
所以我想自动删除,根据使用PowerShell指纹具有特定的模板证书。
答
把它包在一个Where-Object
过滤器:
Get-ChildItem cert:\my\ |Where-Object{
($TmplExt = $_.Extensions |Where-Object {
$_.Oid.FriendlyName -match 'Certificate Template'
}) -and
$TmplExt.format(0) -match 'MyTemplateName'
} |Remove-Item