Skip to content

Instantly share code, notes, and snippets.

@nikanos
Last active October 6, 2025 13:10
Show Gist options
  • Select an option

  • Save nikanos/6fe1c26b2504ee23804d260a9bb74bfc to your computer and use it in GitHub Desktop.

Select an option

Save nikanos/6fe1c26b2504ee23804d260a9bb74bfc to your computer and use it in GitHub Desktop.
Powershell script example to create a self-signed certificate valid for 10 years and stored in Personal store of LocalMachine
# Create a 10-year self-signed certificate for www.abc.cde domain and store it in Personal store of Computer (LocalMachine)
# The command needs to run from an elevated powershell window
New-SelfSignedCertificate -DnsName www.abc.cde -NotAfter (Get-Date).AddYears(10) -CertStoreLocation cert:\LocalMachine\My

Create a 1-year (default) self-signed certificate for 192.168.0.1. We add the IP Address=192.168.0.1 as SAN

New-SelfSignedCertificate -Subject 192.168.0.1 -TextExtension @("2.5.29.17={text}IPAddress=192.168.0.1")

Create a 1-year (default) self-signed certificate for localhost. We add the IP Address=127.0.0.1 and DNS=localhost as SAN

New-SelfSignedCertificate -Subject localhost -TextExtension @("2.5.29.17={text}DNS=localhost&IPAddress=127.0.0.1")

Create a 1-year (default) self-signed certificate for www.abc.cde domain and store it in Personal store of Computer (LocalMachine). We add DNS=www.abc.cde as SAN and specify attributes for CN,OU,O,L,ST,C

New-SelfSignedCertificate -Subject "CN=www.abc.cde, OU=OrgUnit, O=Org, L=Location, ST=State, C=Country" -DnsName www.abc.cde -CertStoreLocation cert:\LocalMachine\My
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment