Cadzow Knowledgebase

Normal view

Scripting: Fetch File Signer

PowerShell can retrieve the certificate information from a binary file. From a scripting perspective it is often useful to extract the Common Name (CN) to validate files. However, the default PowerShell output is difficult to parse because the subject fields are in an unpredictable order and may contain quotes etc:

    powershell (Get-AuthenticodeSignature 'jre-8u251-windows-i586.exe').SignerCertificate.Subject
    [email protected], CN="Oracle America, Inc.", OU=Software Engineering, O="Oracle America, Inc.", L=Redwood City, S=California, C=US

    powershell (Get-AuthenticodeSignature 'c:\windows\explorer.exe').SignerCertificate.Subject
    CN=Microsoft Windows, O=Microsoft Corporation, L=Redmond, S=Washington, C=US

and

    powershell (Get-AuthenticodeSignature 'pkzipc.exe').SignerCertificate.Subject
    OU=Engineering, CN="PKWARE, Inc.", L=Brown Deer, S=Wisconsin, C=US, OU=Digital ID Class 3 - Microsoft Software Validation v2, OU="www.verisign.com/repository/RPA Incorp. by Ref.,LIAB.LTD(c)98", OU=VeriSign Commercial Software Publishers CA, O="VeriSign, Inc.", L=Internet

There is a simple method to determine the CN using a method which is not widely documented:

    powershell (Get-AuthenticodeSignature 'jre-8u251-windows-i586.exe').SignerCertificate.DnsNameList.Unicode
    Oracle America, Inc.

Note this does not seem to work in PowerShell Core.



Copyright © 1996-2023 Cadzow TECH Pty. Ltd. All rights reserved.
Information and prices contained in this website may change without notice. Terms of use.

Question/comment about this page? Please email webguru@cadzow.com.au