I must be using the wrong query because I cannot find how to do in Powershell what I do with a simple:
openssl x509 -in file.pem -text
I guess Powershell provides native commands to show certificate details but I'm struggling in finding how.
CodePudding user response:
The [X509Certificate]::CreateFromCertFile()
method reads Base64 encoded DER cert files natively and works in both Windows PowerShell and newer versions:
$certFile = Get-Item path\to\file.pem
$xCert2Type = [System.Security.Cryptography.X509Certificates.X509Certificate2]
$Certificate = $xCert2Type::CreateFromCertFile($certFile.FullName) -as $xCert2Type
The explicit conversion to [X509Certificate2]
is deliberate - it exposes more metadata via properties and results in nicer default output formatting in PowerShell