You can use Get-PfxData
from pkiclient
.
https://learn.microsoft.com/en-us/powershell/module/pkiclient/get-pfxdata?view=win10-ps
Example:
$mypwd = ConvertTo-SecureString -String "localhost" -Force -AsPlainText
$mypfx = Get-PfxData -FilePath C:\Users\oscar\Desktop\localhost.pfx -Password $mypwd
$mypfx
$mypfx.EndEntityCertificates
If you have the certificate in store and need a .sst
(Microsoft serialized certificate store), .cer
(CERT) or .p7b
(PKCS#7) file you can use Export-Certificate
from pkiclient
(Or Export it via MMC without the private key).
https://learn.microsoft.com/en-us/powershell/module/pkiclient/export-certificate?view=win10-ps
Example for exporting IIS Express generated localhost certificate:
Start mmc.exe.
Then go to:
File -> Add or Remove Snap-ins -> Certificates -> Add -> Computer account -> Local computer
Expand the Personal folder and you will see your localhost certificate.
Double click, go to Details and copy the certificate Thumbprint.
Then run the command:
$cert = (Get-ChildItem -Path cert:\LocalMachine\My\{YourThumbprint})
Export-Certificate -Cert $cert -FilePath C:\Users\oscar\Desktop\localhost.cer
Note: If you need a certificate from your current user then replace LocalMachine
with CurrentUser
in the above command.