- Courses
- đź’»Programming Languages
- 🪟PowerShell
- Enterprise-Grade PowerShell
- Security and Compliance
- Code Signing
On this page
PowerShell Code Signing: Complete Guide
Updated on June 26, 2026
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:
- Authenticity: Is this script really from the person or system it claims to be from? This is tied to the identity embedded in the certificate (your organization, team, or service account).
- Integrity: Has the script been changed since it was signed? If even a single character is modified, the signature becomes invalid.
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:
- Under
AllSigned, unsigned or tampered scripts are blocked. - Under
RemoteSigned, downloaded scripts must be signed to run without prompts.
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:
- An internal PKI (Active Directory Certificate Services or similar), or
- A public CA (for scripts distributed outside the organization).
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:
- The certificate's private key must be available to sign scripts.
- The certificate's trust chain must be valid on the machines where scripts will run.
- Revocation and expiration are enforced during signature validation.
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:
-
Status
Valid— signature is intact and trustedNotSigned— no signature presentUnknownError,HashMismatch, etc. — something is wrong
-
SignerCertificate — shows who signed the script and which certificate was used
-
StatusMessage — explains why a signature is invalid or untrusted (e.g., untrusted root, expired certificate)
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:
- Obtain a code-signing certificate
- Select the certificate in PowerShell
- 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:
- Any modification to the script will invalidate the signature.
Get-AuthenticodeSignaturewill showHashMismatchif the file is altered.
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:
-
Is there a signature?
- If not, and the policy requires signing (
AllSigned,RemoteSignedfor remote scripts), execution is blocked or prompts the user.
- If not, and the policy requires signing (
-
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.
-
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.
-
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:
http://timestamp.digicert.comhttp://timestamp.comodoca.comhttp://timestamp.sectigo.com
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:
-
Developers write scripts
- Scripts live in version control (Git, Azure Repos, etc.).
- Code reviews and approvals happen before merging.
-
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"
-
Deployment only accepts signed artifacts
- Servers enforce
AllSignedorRemoteSigned. - Unsigned or tampered scripts simply do not run.
- Servers enforce
-
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:
AllSigned— Every script must be signed, including local ones. Ideal for high-security or regulated environments. Forces a disciplined signing workflow.RemoteSigned— Local scripts can be unsigned. Scripts from remote sources (internet, email, network shares) must be signed. Good balance between security and developer convenience.Bypass(Process scope) — Nothing is blocked and there are no warnings or prompts. Used for automation agents or tools that must run without prompts.Restricted— Permits individual commands but does not allow scripts.Undefined— No execution policy set in the current scope. The effective policy falls back to Restricted for Windows clients and RemoteSigned for Windows Server.
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:
- It proves who authored a script and whether it has been altered.
- It integrates directly with execution policies to control what can run.
- It fits naturally into CI/CD pipelines and version control.
- It supports long-term auditability through timestamping and certificate management.
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!
Previous
Execution Policies
Next
Credential Management
-
What Code Signing Actually Guarantees
-
The Building Block: The Code-Signing Certificate
- Creating a Self-Signed Certificate
-
Inspecting Script Signatures
-
Signing a Script Step by Step
- Select a Code-Signing Certificate
- Sign the Script
- Using a Certificate from a PFX File
-
How PowerShell Validates Signed Scripts
-
Timestamping: Handling Certificate Expiration
- Including the Trust Chain
-
Code Signing in an Enterprise Workflow
-
How Code Signing Ties Back to Execution Policies
- AllSigned with PowerShell 7+ Considerations
-
Summary
- Quick Reference
