I have this file: https://ufile.io/1j5pleow
it has 4 certificates in its path.
Using this method
$FilePath = '.\NordPassSetup_x86.exe'
# Get the certificate from the file path
$Cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 $FilePath
# Build the certificate chain
$Chain = New-Object System.Security.Cryptography.X509Certificates.X509Chain
[void]$Chain.Build($Cert)
$Chain.ChainElements.count
foreach ($Element in $Chain.ChainElements) {
$Element.Certificate | ft -AutoSize
}
Only returns the shortest chain which only include 3 certificates, but in file explorer I can see the longest/full chain of the certificates, which are 4.
I have other files with similar behavior, one of them has 5 certificates but in PowerShell I can only see 3, because it's the shortest chain.
The question is related to this other one. I was told it's possible to do this using CertGetCertificateChain unmanaged function.
