Public/Get-CertThumbprint.ps1
function Get-CertThumbprint { param ( [ValidateScript( {Test-Path $_})] [string]$Path, [securestring]$Password = (ConvertTo-SecureString -String 'temp1234' -AsPlainText -Force) ) $fileExtension = Get-Item -Path $Path | Select-Object -Property Extension $isPfx = $fileExtension.Extension -eq '.pfx' $certInfo = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 $KeyStorageFlags = [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable -bxor ` [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::MachineKeySet -bxor ` [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::PersistKeySet if ($isPfx) { $certInfo.Import($Path, $Password, $KeyStorageFlags) } else { $certInfo.Import($Path) } $thumbprint = $certInfo.Thumbprint return $thumbprint } |