Is there any way to check for digital signature on a file programmatically in Powershell?

Nilzor picture Nilzor · Nov 9, 2013 · Viewed 10k times · Source

I've a build script which signs a file with a digital certificate (Microsoft Authenticode). I want to create a test script which checks that the file is successfully signed. It's sufficient with a boolean indicating the existence of any signature on the file.

Can I do that with PowerShell without any extensions? If not, what do I need?

Answer

Frode F. picture Frode F. · Nov 9, 2013

Try the Get-AuthenticodeSignature-cmdlet

(Get-AuthenticodeSignature "C:\windows\explorer.exe").Status -eq 'Valid'

True

(Get-AuthenticodeSignature "D:\notes.txt").Status -eq 'Valid'

False