PowerShell icon indicating copy to clipboard operation
PowerShell copied to clipboard

Allow export of whole certificate chain

Open TobiasSonndag opened this issue 5 months ago • 0 comments

https://github.com/J0F3/PowerShell/blob/71ad3619a08a58cf770fe23f7cfe55b309ac0d53/Request-Certificate.ps1#L406 For some certificates you need the whole chain to be exported (For example VMWare vCenter). I adapted your script and maybe you can add it here.

Solution taken from: https://stackoverflow.com/questions/33512409/automate-export-x509-certificate-w-chain-from-server-2008-r2-to-a-p7b-file-witho

New paramter [Parameter(Mandatory = $False, ValueFromPipelineByPropertyName = $True, ParameterSetName='Export')] [switch]$ExportIncludeAllCerts

New code $certs = New-Object Security.Cryptography.X509Certificates.X509Certificate2Collection if ($ExportIncludeAllCerts) { $chain = New-Object Security.Cryptography.X509Certificates.X509Chain $chain.ChainPolicy.RevocationMode = "NoCheck" [void]$chain.Build($cert) $chain.ChainElements | ForEach-Object {[void]$certs.Add($_.Certificate)} $chain.Reset() } else { [void]$certs.Add($Certificate) }

Thanks for your code, helped me a lot!

TobiasSonndag avatar Sep 10 '24 08:09 TobiasSonndag