Get AuthenticodeSignature - PowerShell


Overview

Get-AuthenticodeSignature retrieves Authenticode signatures from files, providing insights into their digital signing and authenticity. This command is invaluable for verifying software integrity and detecting malicious code or tampering.

Syntax

Get-AuthenticodeSignature [-FilePath] <String[]> [-Verbose] [-Debug] [-ErrorAction] <ActionPreference> [-ErrorVariable] <String> [-OutVariable] <String>

Options/Flags

  • -FilePath: Path to the file(s) to retrieve signatures from. Multiple file paths can be specified as an array.
  • -Verbose: Enables verbose output, providing detailed information about the signature verification process.
  • -Debug: Enables debug output, displaying diagnostic messages for troubleshooting purposes.
  • -ErrorAction: Controls how errors are handled. Can be set to Stop, Continue, SilentlyContinue, or Inquire.
  • -ErrorVariable: Stores any errors encountered during command execution in the specified variable.
  • -OutVariable: Stores the output of the command in the specified variable.

Examples

Example 1: Verify Single File Signature

Get-AuthenticodeSignature -FilePath "path\to\file.exe"

Example 2: Check Multiple Signatures

Get-AuthenticodeSignature -FilePath @( "path\to\file1.exe", "path\to\file2.dll" )

Example 3: Verbose Output for Signature Inspection

Get-AuthenticodeSignature -FilePath "path\to\file.exe" -Verbose

Common Issues

  • Missing or Invalid Certificates: The signature may not be verified if the necessary certificates are missing or invalid. Ensure proper certificate authorities are installed and trusted.
  • Corrupted Files: If the file has been corrupted, the signature verification may fail. Check file integrity or attempt to download the file again from a trusted source.
  • Certificate Revocation: The certificate used for signing may have been revoked. Use the Internet Explorer Certificate Manager (certmgr.msc) to check certificate status.

Integration

Command Chain: Combine Get-AuthenticodeSignature with New-Object to create a custom signature validation script.

$signature = Get-AuthenticodeSignature -FilePath "path\to\file.exe"
New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList $signature.SignerCertificate