0

I'm working on an export script. I am however stucked because unable to export my certificates by including those in the certification path.

I would like to reproduce this option in my script.

$ChainCertName = "fooCert"  # name of the certificate to export
$ChainIssuerName = "BarCert"        # certificate issuer

# search for a certificate which contains the requested name and provided by the requested issuer
$ChainCertListToExport = Get-ChildItem -Path cert:\CurrentUser\CA | ?{$_.Subject -Like "*CN=*$ChainCertName*" -and $_.Issuer -Like "CN=$ChainIssuerName*"}

foreach($ChainCertToExport in $ChainCertListToExport | Sort-Object Subject){

    # export P7B certificate
    $ChainCertDestPath = Join-Path -Path $ExportDirectory -ChildPath "Chain_certificate.p7b"
    Export-Certificate -Cert $ChainCertToExport -FilePath $ChainCertDestPath -Type p7b
}

I was able to see that some solutions could be found with the function Export-PfxCertificate but I have not yet found anything for p7b.

If someone had this problem, can you share your solution please ?

Alewc9
  • 1
  • 2
  • Dropped my answer, since we still do not have a match, the Export-PfxCertificate, does pfx, which means you need to use tools to convert that to P7b or as in my previous comment, look to external tools: Certutil - Export root and intermediate CA certificates in base64 format using PowerShell on the intermediate CA https://social.technet.microsoft.com/Forums/en-US/b4e479fd-48b7-4659-ac02-6e7eadd1bdda/export-root-and-intermediate-ca-certificates-in-base64-format-using-powershell-on-the-intermediate or the like. – postanote Oct 20 '20 at 16:14

1 Answers1

0

If you just need to export certificates in .p7b format use below command:

Get-ChildItem -Path Cert:\CurrentUser\CA | Export-Certificate -FilePath c:\certs\CA.p7b -Type P7B

More details can be found at the link.

Buch
  • 1