liveBook · Manning

Self-signed certificate

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

A self-signed certificate is a digital certificate signed by its own subject rather than by an independent certificate authority.

A self-signed certificate is signed by its own subject instead of an independent certificate authority. It is convenient for signing PowerShell scripts during development or for personal desktop use, but it should be replaced with a trusted certificate when code is shared. section 21.2

Use a self-signed certificate with these boundaries in mind:

  • Create one for testing or scripts that never leave your desktop. section 21.4.1
  • Use an internal PKI or commercial certificate when distributing code to others. section 21.2
  • Protect the private key carefully, including with password protection in the Windows certificate store. section 21.2
  • Trust the certificate’s root locally before using it, because a computer does not automatically trust certificates it creates. section 21.4.2

Create a code-signing certificate

Run New-SelfSignedCertificate with the CodeSigningCert type, your own CN subject, the current-user certificate store, and the -TestRoot parameter. PowerShell may initially report an unknown error because the certificate chain is untrusted. section 21.4.1

PS Cert:\> New-SelfSignedCertificate -type CodeSigningCert -Subject
"CN=James Petty" -CertStoreLocation Cert:\CurrentUser\My\ -testroot
   PSParentPath: Microsoft.PowerShell.Security\Certificate::CurrentUser\My
 
Thumbprint                                 Subject     EnhancedKeyUsageList
----------                                 -------             -----------
F33E9122D73BE220117339E9647F0037F3F875A6  CN=James Petty       Code Signing
 

Use this listing as a concrete template for creating a self-signed PowerShell code-signing certificate, then replace the subject name. section 21.4.1

PS C:\> dir Cert:\CurrentUser\My\ -CodeSigningCert
   PSParentPath: Microsoft.PowerShell.Security\Certificate::CurrentUser\My
Thumbprint                                Subject
----------                                -------
F33E9122D73BE220117339E9647F0037F3F875A6CN=James Petty

Use the certificate-store listing to locate installed code-signing certificates and identify the one to use by its thumbprint. section 21.4.1

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

How deep it goes
Explains creation, certificate discovery, private-key protection, and local root trust, while deferring internal PKI details.
Examples
Uses New-SelfSignedCertificate, Cert:\CurrentUser\My, thumbprints, and Certmgr.msc to create, locate, and trust certificates.
What it assumes
Assumes basic PowerShell and certificate-store familiarity while teaching certificate trust and self-signed creation procedurally.
What you can do after
Apply it via PowerShell to create and locate a local code-signing certificate and configure its root as trusted.
How it connects
Connects code signing with certificate authorities, public key infrastructure, private keys, certificate chains, and trust stores.

Also explained in

Compare how 4 books explain self-signed certificate →

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.