Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell Get Certificate Thumbprint with Password PFX File

Tags:

I'm trying to get the thumbprint of a password protected pfx file using this code:

function Get-CertificateThumbprint {     #      # This will return a certificate thumbprint, null if the file isn't found or throw an exception.     #      param (         [parameter(Mandatory = $true)][string] $CertificatePath,         [parameter(Mandatory = $false)][string] $CertificatePassword     )      try {         if (!(Test-Path $CertificatePath)) {             return $null;         }          if ($CertificatePassword) {             $sSecStrPassword = ConvertTo-SecureString -String $CertificatePassword -Force –AsPlainText         }          $certificateObject = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2         $certificateObject.Import($CertificatePath, $sSecStrPassword);          return $certificateObject.Thumbprint     } catch [Exception] {         #          # Catch accounts already added.         throw $_;     } } 

When I run it, I get this error:

Cannot find an overload for "Import" and the argument count: "2". At C:\temp\test.ps1:36 char:9 +         $certificateObject.Import($CertificatePath, $sSecStrPassword); +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + CategoryInfo          : NotSpecified: (:) [], MethodException     + FullyQualifiedErrorId : MethodCountCouldNotFindBest 

Can someone please help me sort this out?

Thanks All. :-)

like image 753
flipcode Avatar asked Nov 12 '14 00:11

flipcode


People also ask

How do I get a PFX certificate thumbprint?

Double-click the certificate. In the Certificate dialog box, click the Details tab. Scroll through the list of fields and click Thumbprint. Copy the hexadecimal characters from the box.

How do I get the thumbprint of a certificate in PowerShell?

All you have to do is wrap the command in parentheses, and then use dot-notation to access the Thumbprint property. Try this out: $Thumbprint = (Get-ChildItem -Path Cert:\LocalMachine\My | Where-Object {$_. Subject -match "XXXXXXX"}).

How do I find the thumbprint of a certificate?

Go to Tools > Internet Options. Click Content tab > Certificates. In the Certificates window, click on the tab for the certificate you want to examine (Personal, Other People, Intermediate Certification Authorities, Trusted Root Certification Authorities) Locate the certificate or root in the list.


1 Answers

According to this SuperUser response, in PS 3.0 there is Get-PfxCertificate command to do that:

 Get-PfxCertificate -FilePath Certificate.pfx  
like image 175
Nikita R. Avatar answered Oct 10 '22 09:10

Nikita R.