Question:
I need to use a PowerShell script to pick the certificate with “Certificate Template Name” as “Machine.” In certmgr.msc, this has “Certificate Template” with value of “Computer.” In Details, the same one has “Certificate Template Name” as “Machine.”
How can I use either of these values in a PowerShell script?
Thus far, I have:
1 2 |
get-childitem cert:\localmachine\my | where-object {$_.} |
I’ve tried just about every method that intellisense loads, but have not been able to find anything that meets my needs.
Thank You,
Answer:
Here is a solution sans-modules:
1 2 3 |
$templateName = 'Super Cool *' Get-ChildItem 'Cert:\LocalMachine\My' | Where-Object{ $_.Extensions | Where-Object{ ($_.Oid.FriendlyName -eq 'Certificate Template Information') -and ($_.Format(0) -match $templateName) }} |