Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 728
Nilzor Avatar asked Nov 09 '13 13:11

Nilzor


People also ask

How do you check if a file has a digital signature?

Open the file that contains the digital signature you want to view. Click File > Info > View Signatures. In the list, on a signature name, click the down-arrow, and then click Signature Details.

How can I tell if a PowerShell script is digitally signed?

Opening the Script's File Properties Another way to check the script's digital signature is to open the script's file properties in Windows Explorer. To do so: In Windows Explorer, navigate to the PowerShell script's location. In this example, the script is in C:\ATA\myscript.

How can I tell if an EXE file is signed?

From a Windows operating system: Right click the file the main executable file (.exe), select Properties > Digital Signatures. Under Signature list, select the Signature, and click Details. You will see information regarding the Code Signing certificate that was used to sign the executable.

How do you check if a DLL is digitally signed?

Open the properties sheet for the . dll from Windows Explorer. If a tab "Digital Signatures" is shown, it's a signed assembly. If the tab is missing, it's unsigned.


2 Answers

Try the Get-AuthenticodeSignature-cmdlet

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

True

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

False
like image 197
Frode F. Avatar answered Oct 13 '22 11:10

Frode F.


You could simply call signtool.exe to verify the result.

like image 32
jessehouwing Avatar answered Oct 13 '22 10:10

jessehouwing