Skip to content

Instantly share code, notes, and snippets.

@nikanos
Last active April 8, 2024 07:55
Show Gist options
  • Save nikanos/6fe1c26b2504ee23804d260a9bb74bfc to your computer and use it in GitHub Desktop.
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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment