Set-AuthenticodeSignature
Use Set-AuthenticodeSignature to sign a script with a code-signing certificate, proving origin and integrity.
Documentation: Microsoft Learn — Set-AuthenticodeSignature
Syntax
See the command anatomy
Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.
Set-AuthenticodeSignature [-FilePath] <String[]> [-Certificate] <X509Certificate2> [-IncludeChain <String>] [-TimestampServer <String>] [-HashAlgorithm <String>] [-Force] [-WhatIf] [<CommonParameters>]- Stage 1Set-AuthenticodeSignature
-FilePath -Certificate -IncludeChain -TimestampServer -HashAlgorithm -Force -WhatIf
Try it
PowerShell example · browser support is limited.
Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.
Follow the objects
Run the command to inspect each stage.
Examples
Select first 1
Show reference output
Sample output · fictional data, shaped like the real thing
SignerCertificate Status Path ----------------- ------ ---- CN=Contoso Code Signing Valid C:\Scripts\Backup-Files.ps1
Select first 1 (2)
Show reference output
Sample output · fictional data, shaped like the real thing
Status ------ Valid
Select Status
Show reference output
Sample output · fictional data, shaped like the real thing
SignerCertificate Status StatusMessage Path ----------------- ------ ------------- ---- CN=Microsoft Corporation, O=Microsoft... Valid Signature verified script.ps1
Parameters
Parameter definitions:
-FilePath-Certificate-IncludeChain-TimestampServer-HashAlgorithm-Force-WhatIf
Practical use and troubleshooting
Practical scenario: Use Set-AuthenticodeSignature when you need to sign a script with a code-signing certificate, proving origin and integrity. Start with one identified target and inspect the returned values before extending the operation to a list. Keep the identity in your report so you can trace each result back to the object or path that produced it.
Common error and fix: A missing or unsuitable certificate can prevent signing. Check code-signing usage, private-key availability and trust requirements instead of selecting any certificate from the store. In an unattended script, capture this failure with its original error record and record which target failed. An empty result and an unsuccessful query must remain distinguishable in the final report.
See also: Get-FileHash. Set-AuthenticodeSignature signs supported files with a certificate; Get-FileHash calculates a digest. A signature requires a suitable signing certificate and its private key. Read the linked command before substituting it; similar names do not imply identical inputs or output.
Recap
Set-AuthenticodeSignature Use Set-AuthenticodeSignature to sign a script with a code-signing certificate, proving origin and integrity.
Next: Get-AuthenticodeSignature