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 ?