I'm trying to write a script which validates certificate chain in PowerShell (that all certificates in the chain are not expired) and finds the certificate which is closest to expiration. I'm using following script to find issuer certificate:
Get-ChildItem -Recurse -Path Cert: | Where-Object {...