liveBook · Manning

Code signing

As explained in Learn PowerShell Scripting in a Month of Lunches, Second Edition: Write and organize scripts and tools

A signed script is a script containing a verifiable digital signature that identifies its signer and reveals subsequent content changes.

Code signing adds a verifiable digital signature to a script, identifying its signer and revealing changes made after signing. It is a practical habit for protecting automation, especially when scripts leave your organization, and works alongside source control. section 21.0 section 21.1

A signed script provides two related checks:

  • It authenticates the author, helping trace a script to its creator without guaranteeing that the script is safe or well designed. section 21.1
  • It verifies integrity, allowing PowerShell to identify accidental or malicious changes made after signing. section 21.1
  • It requires an environment that enforces signatures; signing files alone is insufficient. section 21.3

Choose a certificate for the deployment context

A commercial certificate authority typically issues Class 3 code-signing certificates after rigorous identity verification, often to organizations. An internal public key infrastructure and certificate authority suit organizational code, while a self-signed certificate is convenient for code used only by its individual maintainer and should be replaced before distributing it to others. section 21.2

Make PowerShell enforce signatures

On a machine that runs scripts, configure the execution policy in an elevated PowerShell session. Use AllSigned where scripts should require signatures; remote servers that rarely run interactive scripts may remain Restricted. Group Policy can configure execution policies in an Active Directory domain. section 21.3

Set-Executionpolicy AllSigned -force

Use the supplied command to require signed scripts while suppressing the confirmation prompt. section 21.3

How Learn PowerShell Scripting in a Month of Lunches, Second Edition: Write and organize scripts and tools covers it

How deep it goes
Explains signing benefits, certificate choices, and enforcement configuration, while deferring detailed public key infrastructure.
Examples
Uses scripts from Sally or blogs, accidental edits by coworkers, certificate deployment contexts, and the AllSigned execution-policy command.
What it assumes
Assumes PowerShell familiarity and introduces certificates, certificate authorities, PKI, and execution-policy enforcement.
What you can do after
Operate/configure PowerShell to require signed scripts and select certificates appropriate for development or organizational deployment.
How it connects
Connects certificates, certificate authorities, public key infrastructure, source control, execution policies, and Active Directory.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn PowerShell Scripting in a Month of Lunches, Second Edition: Write and organize scripts and tools. The section links point to the parts of the book it draws on.