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. :-)
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.
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"}).
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.
According to this SuperUser response, in PS 3.0 there is Get-PfxCertificate command to do that:
Get-PfxCertificate -FilePath Certificate.pfx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With