I have a signed file that for some reason can't get its root certificate in PowerShell using the code below
$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
}
Uploaded the file here: https://ufile.io/1j5pleow
The output is 3 items instead of 4 items. The file has 1 leaf, 1 root and 2 intermediate certificates.
I've tried skipping check for root cert and setting the check to offline but didn't help
[System.Security.Cryptography.X509Certificates.X509RevocationMode]::Offline
[System.Security.Cryptography.X509Certificates.X509RevocationFlag]::ExcludeRoot
The highlighted certificate doesn't show up in command line

I finally figured out a way to do this and it works beautifully. Leaf certificate, Root certificate, Intermediate certificate(s) and nested certificates are all detected and processed. The code is part of my module and available here:
https://github.com/HotCakeX/Harden-Windows-Security/blob/main/WDACConfig/Invoke-WDACSimulation.psm1
First I made this function to get the certificate collection of the signed file
Then I modified one of my previous functions accordingly to handle the new type of data