Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have some certificates on Windows. These certs has different templates.

I can get thumbprints:

$Certificates = get-childitem cert:LocalMachineMy

I can get templates:

$Template = ($Certificates.extensions | where-object{$_.oid.FriendlyName -match "Certificate Template Information"}).format(0)

So I want to automate deleting cert that has specific template according to thumbprint with powershell.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
293 views
Welcome To Ask or Share your Answers For Others

1 Answer

Wrap it in a Where-Object filter:

Get-ChildItem cert:my |Where-Object{
  ($TmplExt = $_.Extensions |Where-Object {
    $_.Oid.FriendlyName -match 'Certificate Template'
  }) -and 
  $TmplExt.format(0) -match 'MyTemplateName'
} |Remove-Item 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...