PowerShell Genie

Set-AuthenticodeSignature

Use Set-AuthenticodeSignature to sign a script with a code-signing certificate, proving origin and integrity.

Command 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn — Set-AuthenticodeSignature

Syntax

1PS> Set-AuthenticodeSignature [-FilePath] <String[]> [-Certificate] <X509Certificate2> [-IncludeChain <String>] [-TimestampServer <String>] [-HashAlgorithm <String>] [-Force] [-WhatIf] [<CommonParameters>]
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>]
  1. Stage 1Set-AuthenticodeSignature-FilePath -Certificate -IncludeChain -TimestampServer -HashAlgorithm -Force -WhatIf

    Try it

    Windows PowerShell

    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.

    Interactive simulation · fictional data

    Examples

    Select first 1

    1PS> $cert = Get-ChildItem Cert:\CurrentUser\My -CodeSigningCert | Select-Object -First 1
    2PS> Set-AuthenticodeSignature -FilePath C:\Scripts\Backup-Files.ps1 -Certificate $cert
    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)

    1PS> $cert = Get-ChildItem Cert:\CurrentUser\My -CodeSigningCert | Select-Object -First 1
    2PS> Set-AuthenticodeSignature -FilePath C:\Scripts\Backup-Files.ps1 -Certificate $cert -TimestampServer http://timestamp.digicert.com
    Show reference output

    Sample output · fictional data, shaped like the real thing

    Status
    ------
     Valid

    Select Status

    1PS> Get-AuthenticodeSignature C:\Scripts\Backup-Files.ps1 | Select-Object 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

    Set-AuthenticodeSignature on Microsoft Learn

    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.

    Set-AuthenticodeSignature reference on Microsoft Learn

    Recap

    Set-AuthenticodeSignature Use Set-AuthenticodeSignature to sign a script with a code-signing certificate, proving origin and integrity.

    Next: Get-AuthenticodeSignature
    Genie guideSet-AuthenticodeSignature

    Use Set-AuthenticodeSignature to sign a script with a code-signing certificate, proving origin and integrity. The console below is pre-loaded — run it, then change a value and run it again.