Search code examples
shellscriptingpowershell-4.0

Getting certificate thumbprint with no unique data


I am using the following powershell search to get 3 certificate thumbprints for a user account.

get-childitem -path $certPath | where-object {$_.Subject -match "$Displayname"} | Where-Object {$_.EnhancedKeyUsageList -match "EKU OID"}

Two of the certificates have an Enhanced Key Usage that I can easily search for. One of the certificates does not have an Enhanced Key Usage. I have tried various comparisons to search for a null value, but all of my searches return the other two certs. I have tried -match, -notmatch, -like, and -notlike. Any suggestions on how I can single out this certificate?


Solution

  • I was able to get the certificate by using the following search parameters

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

    I found the example from this post: How can I delete certificate that has specific template?