On this page

PowerShell Code Signing: Complete Guide

Updated on June 26, 2026

Enrico Hochkoeppler Profile

By Enrico Hochkoeppler

Web Developer & TutoriaLibre Founder

Code signing is the mechanism that lets you prove who authored a PowerShell script and whether it has been modified since it was approved. In enterprise environments, this is not optional—it is the backbone of trustworthy automation. When combined with execution policies such as AllSigned or RemoteSigned, code signing transforms scripts from text files into controlled, auditable assets. This guide covers the complete workflow: obtaining certificates, signing scripts, validating signatures, integrating with CI/CD pipelines, and maintaining long-term compliance through timestamping.


What Code Signing Actually Guarantees​

A signed script carries a digital signature created with a code-signing certificate. When PowerShell validates that signature, it answers two fundamental questions:

PowerShell checks Authenticode signatures on the following file types: .ps1 script files, .psm1 module files, .psd1 module manifests, .ps1xml type and format files, .cdxml CDXML script files, and .xaml XAML script files.

PowerShell uses these guarantees to decide whether a script is allowed to run under the current execution policy. For example:

Important: The execution policy is not a security boundary. Users can bypass it by typing script contents directly at the command line. Instead, the execution policy helps users set basic rules and prevents them from violating them unintentionally.


The Building Block: The Code-Signing Certificate​

To sign scripts, you need a code-signing certificate. This is an X.509 certificate with a specific usage: it is allowed to sign code.

In an enterprise, this usually comes from:

The certificate must be installed in the user's personal certificate store so PowerShell can access it:


Get-ChildItem -Path Cert:\CurrentUser\My -CodeSigningCert

Code explanation: This command lists all certificates in the CurrentUser\My store that are valid for code signing. The -CodeSigningCert parameter, supported only by the Certificate provider, limits the retrieved certificates to those with code-signing authority. If this returns nothing, you do not have a usable code-signing certificate in that profile.

Key points:

Creating a Self-Signed Certificate​

For testing or internal use, you can create a self-signed certificate using the New-SelfSignedCertificate cmdlet in the PKI module:


New-SelfSignedCertificate -Subject "CN=PowerShell Code Signing" -CertStoreLocation Cert:\CurrentUser\My -Type CodeSigningCert -KeyUsage DigitalSignature

Code explanation: This creates a code-signing certificate with the specified subject name and stores it in the current user's personal certificate store. The -Type CodeSigningCert ensures the certificate is suitable for signing code.

Important: Self-signed certificates must be installed in the Trusted Root Certificates store on every computer where the signed scripts will run. For production environments, use certificates from a trusted CA.


Inspecting Script Signatures​

Before you can trust a script, you need to know whether it is signed and whether that signature is valid. PowerShell exposes this via Get-AuthenticodeSignature:


Get-AuthenticodeSignature .\Deploy.ps1

Important fields in the output:

This is how you programmatically enforce "only signed scripts from our org are allowed" in tooling, CI/CD, or pre-deployment checks.


Signing a Script Step by Step​

The basic workflow to sign a script is:

  1. Obtain a code-signing certificate
  2. Select the certificate in PowerShell
  3. Apply the signature to the script

Select a Code-Signing Certificate​


$cert = Get-ChildItem -Path Cert:\CurrentUser\My -CodeSigningCert | Select-Object -First 1

Code explanation: This picks the first available code-signing certificate in the current user's store. In a real environment, you might filter by subject, issuer, or thumbprint to ensure you are using the correct one.

Sign the Script​


Set-AuthenticodeSignature -FilePath .\Deploy.ps1 -Certificate $cert

Code explanation: The Set-AuthenticodeSignature cmdlet calculates a hash of the script, signs that hash with the certificate's private key, and embeds the signature into the script as a comment block at the end. If a signature already exists in the file, it is removed and replaced.

From this point on:

Using a Certificate from a PFX File​

For certificates stored in a PFX file:


$cert = Get-PfxCertificate -FilePath "C:\Certificates\MySigningCert.pfx"

Set-AuthenticodeSignature -FilePath .\Deploy.ps1 -Certificate $cert

Code explanation: Get-PfxCertificate loads the certificate from the PFX file, prompting for the password if required.


How PowerShell Validates Signed Scripts​

When you run a signed script, PowerShell performs several checks:

  1. Is there a signature?

    • If not, and the policy requires signing (AllSigned, RemoteSigned for remote scripts), execution is blocked or prompts the user.
  2. Is the signature intact?

    • PowerShell recomputes the hash of the script and compares it with the signed hash.
    • If they differ, the script has been modified → execution is blocked.
  3. Is the certificate trusted?

    • The certificate chain must lead to a trusted root CA.
    • If the root or intermediate CA is not trusted, the signature is treated as untrusted.
  4. Is the certificate valid and not revoked?

    • Expired or revoked certificates cause validation to fail.
    • CRL/OCSP checks may be performed depending on configuration.

Only if all checks pass does PowerShell treat the script as trusted under the current execution policy.


Timestamping: Handling Certificate Expiration​

Certificates expire. If you do nothing special, a script signed with an expired certificate will fail validation—even if the script itself has not changed.

To avoid this, enterprises use timestamp servers when signing:


Set-AuthenticodeSignature `

    -FilePath .\Deploy.ps1 `

    -Certificate $cert `

    -TimestampServer "http://timestamp.digicert.com"

Code explanation: The -TimestampServer parameter adds a timestamp to the signature. The timestamp server attests: "This script was signed at this date and time, when the certificate was still valid." Even after the certificate expires, the signature remains valid because it was valid at the time of signing.

Common timestamp servers include:

This is crucial for long-lived automation and for compliance audits that may review scripts years later.

Including the Trust Chain​

You can also include the entire trust chain in the signature:


Set-AuthenticodeSignature `

    -FilePath .\Deploy.ps1 `

    -Certificate $cert `

    -IncludeChain All

Code explanation: The -IncludeChain parameter includes all signatures in the trust chain, including the root authority. This can help with validation on systems that may not have the intermediate certificates installed.


Code Signing in an Enterprise Workflow​

In a serious environment, code signing is not something developers do manually once in a while—it is part of the delivery pipeline.

A typical enterprise pattern looks like this:

  1. Developers write scripts

    • Scripts live in version control (Git, Azure Repos, etc.).
    • Code reviews and approvals happen before merging.
  2. Build/CI pipeline validates and signs

    • Linting, tests, and security checks run.
    • On success, the pipeline uses a central code-signing certificate (often stored in a secure vault or HSM) to sign the scripts:

$cert = Get-ChildItem -Path Cert:\LocalMachine\My -CodeSigningCert |

    Where-Object { $_.Subject -like '*CN=Org Code Signing*' } |

    Select-Object -First 1

Set-AuthenticodeSignature -FilePath .\Out\Deploy.ps1 -Certificate $cert -TimestampServer "http://timestamp.digicert.com"
  1. Deployment only accepts signed artifacts

    • Servers enforce AllSigned or RemoteSigned.
    • Unsigned or tampered scripts simply do not run.
  2. Audit and compliance

    • Every signed script can be traced back to a certificate and a pipeline run.
    • Certificate revocation can instantly invalidate compromised signing identities.

This turns PowerShell scripts into controlled, auditable assets, not random files copied around by hand.


How Code Signing Ties Back to Execution Policies​

Execution policies and code signing are designed to work together:

Code signing is what makes these policies enforceable in a meaningful way. Without signing, execution policies can only distinguish "local vs remote" or "script vs no script"—they cannot distinguish trusted from untrusted code.

AllSigned with PowerShell 7+ Considerations​

When using AllSigned with PowerShell 7+, modules signed by Microsoft and shipped with Windows may not be trusted by default. This is because the execution policy can interfere with loading Microsoft-signed modules. Organizations should test their signing policies thoroughly and consider using RemoteSigned for general-purpose environments while enforcing signing through other controls.


Summary​

Code signing is a non-negotiable part of enterprise PowerShell automation:

Once you internalize this, you stop thinking of scripts as loose files and start treating them as signed, governed artifacts—which is exactly the mindset required for enterprise-grade PowerShell.

Quick Reference​

TaskCommandList code-signing certificatesGet-ChildItem Cert:\CurrentUser\My -CodeSigningCertSign a scriptSet-AuthenticodeSignature -FilePath script.ps1 -Certificate $certSign with timestampSet-AuthenticodeSignature -FilePath script.ps1 -Certificate $cert -TimestampServer "http://timestamp.digicert.com"Inspect a signatureGet-AuthenticodeSignature script.ps1Load certificate from PFX$cert = Get-PfxCertificate -FilePath "cert.pfx"Create self-signed certificateNew-SelfSignedCertificate -Subject "CN=Code Signing" -CertStoreLocation Cert:\CurrentUser\My -Type CodeSigningCertSet execution policySet-ExecutionPolicy -ExecutionPolicy AllSigned -Scope LocalMachine

Found this helpful? Share the knowledge...

... or support this project to keep it alive!

Buy Me a Coffee

Previous

Execution Policies

Next

Credential Management