PKCS7 (p7b) bag of certificates and powershell


Recently I was asked how to extract the certificates within a PKCS7 (p7b) files using powershell. After a little research the following seems to work fine:


[reflection.assembly]::LoadWithPartialName("System.Security")
$data = [System.IO.File]::ReadAllBytes("certificates.p7b")
$cms = new-object system.security.cryptography.pkcs.signedcms
$cms.Decode($data)
$cms.Certificates | foreach {New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 $_} | echo


 

Comments (2)
  1. Steve says:

    I am looking for something like this but this ps1 seems to just print out the details of the certs… could you give a sample of how you could actully export the certs as individual cert files (for example  *1.cer, *2.cer etc)

Comments are closed.

Skip to main content