How to Create Self-signed Certificate using PowerShell (2024)

As an administrator, ensuring secure communication over networks is a top priority. One way to achieve this is by using secure certificates. While CA-signed certificates (issued by a trusted third-party organization) provide a high level of security, they can be expensive and may not be necessary for all use cases. In such scenarios, a self-signed public certificate can serve cost-effective and convenient alternative.

Self-signed certificates are perfect for testing purposes and provide a secure solution for administrators who require a certificate-based solution. With just a single PowerShell cmdlet, you can easily create an SSL certificate that fits your needs and requirements.

This blog provides a comprehensive guide on creating certificates for various purposes, making the process simple and straightforward for administrators.

  • Createown SSL certificate with PowerShell
  • Export self-signed certificate using PowerShell
  • Find certificate expiration date
  • Create self-signed certificate with longer expiry date
  • How to use single certificate for multiple domains?
  • Clone an existing SSL certificate
  • Generate code-signing certificate
  • Delete self-signed certificate

Create Your Own SSL Certificate using PowerShell

This is simple as it looks. Using the ‘New-SelfSignedCertificate’ cmdlet, you can create self-signed certificate in a jiffy.

$Certificate=New-SelfSignedCertificate –Subject testing.com -CertStoreLocation Cert:\CurrentUser\My
How to Create Self-signed Certificate using PowerShell (1)

The above cmdlet will create a self-signed SSL server authentication certificate for the domain testing.com in the current user certificate store. By default, the certificate is valid for a year. You can set expiry through ‘NotAfter’ parameter. We will see additional parameter details later in the blog.

Note: When you create a certificate in the current user store, it is only available to the current user, whereas creating the certificate in Cert:\LocalMachine\My makes it available to all users on the local machine.

Export Self-signed Certificate using PowerShell

To export the certificate from certificate store to file, run the ‘Export-Certificate’ cmdlet.

The $Certificate variable in the previous command stores your certificate in the current session and allows you to export it.

Export-Certificate -Cert $Certificate -FilePath "C:\$certname.cer"

Now, the certificate is exported and stored in the given ‘FilePath.’

To export a specific certificate, you can use the following example

$Certificate=Get-ChildItem –Path <Certificate path>
Export-Certificate -Cert $Certificate -FilePath "C:\Users\admin\Desktop\$certname.cer"
How to Create Self-signed Certificate using PowerShell (2)

You can use the certificate’s Thumbprint for further use. For example, if you are an Office 365 admin, you can use it to connect MS Graph PowerShell with certificate.

To export all the certificates available under cert:\CurrentUser\my store, run the below cmdlet

Get-ChildItem -Path cert:\CurrentUser\my | Export-Certificate -FilePath c:\certs\allcerts.sst

When you export a single certificate, the default format is CERT. If you export multiple certificates, the default format is SST. You can use ‘Type’ parameter to change the file type.

Export Certificate with Private Key:

If your application or script running from another machine or cloud, you can export the certificate with the private key.

$Pwd = ConvertTo-SecureString -String "Testing" -Force -AsPlainTextExport-PfxCertificate -Cert $Certificate -FilePath "D:\$certname.pfx" -Password $Pwd

The private key (.pfx file) is encrypted and can’t be read by other users.

Find Certificate Expiration Date with PowerShell

Self-signed certificates have limited time span. By default, it has one year from the creation date. But we can set expiry while creating the certificate.

To view certificate expiry date, run the following cmdlet.

Get-ChildItem -path <CertPath> | select ThumbPrint,Subject,NotAfter

You can use the below PowerShell script to check expiry date for all the SSL certificates in the current user store.

Get-ChildItem -path Cert:\CurrentUser\My | select ThumbPrint,Subject,NotAfter

Create Self-signed SSL Certificate with Longer Expiry:

With PowerShell, you can set or customize certificate expiry date during creation. To create self-signed certificate with a specific validity, you can create it with ‘NotBefore’ and ‘NotAfter’ parameters.

For example, the below cmdlet creates certificate with 36 months validity.

$Certificate=New-SelfSignedCertificate –Subject testing.com -CertStoreLocation Cert:\CurrentUser\My -NotAfter (Get-Date).AddMonths(36)
How to Create Self-signed Certificate using PowerShell (3)

You can also use .AddYears(<RequiredYears>, to set certificate expiry in years. For example,

$Certificate=New-SelfSignedCertificate –Subject testing.com -CertStoreLocation Cert:\CurrentUser\My -NotAfter (Get-Date).AddYears(5)

The above cmd creates a certificate with 5 years validity.

How to Use Single Self-Signed Certificate for Multiple Domains?

“Is it possible to use a single self-signed SSL certificate for multiple domains?” Yes, it is indeed possible. This is a common question asked in various technical forums.

By utilizing a single self-signed SSL certificate for multiple domains, you can streamline your certificate management and reduce administrative overhead compared to having a separate certificate for each individual site. This can be achieved by creating one certificate with Subject Alternative Name (SAN).

Let’s explore how to create a SAN certificate for multiple sites.

You can use ‘DNSName’ parameter to mention a multiple subject as follows.

New-SelfSignedCertificate -DnsName "www.fabrikam.com", "www.contoso.com" -CertStoreLocation "cert:\LocalMachine\My"
How to Create Self-signed Certificate using PowerShell (4)

The given example creates a self-signed SSL certificate for multiple websites as shown in the ‘DNSNameList’ attribute. The first string in the ‘DNSNameList’ considered as a certificate’s Subject.

How to Clone Existing SSL Certificate?

You cannot renew expired self-signed certification but you can use the cloning feature to prevent the need to create a new certificate from scratch.

Cloned certificate inherits the properties from old certificate except Publickey, Thumbprint, NotBefore, and NotAfter properties.

$CertToBeCloned= Get-ChildItem -path <CertPath> 
New-SelfSignedCertificate -CloneCert $CertToBeCloned
How to Create Self-signed Certificate using PowerShell (5)


If you create a clone certificate without specifying NotBefore and NotAfter parameter, the cloned certificate will have the same validity period from the date of creation. If you want to modify validity period, you can use the NotBefore and NotAfter parameters while creation.

How to Create Code Signing Self-Signed Certificate?

You can use code signing certificates to sign your PowerShell scripts and applications. It’s important to note that self-signed code signing certificates are not automatically trusted by the operating system and applications. As a result, they should only be used for testing purposes, and not for production or other critical systems.

To create code-signing certificate, run the below cmdlet

$Cert = New-SelfSignedCertificate -Type CodeSigningCert -Subject "testingScripts" -CertStoreLocation Cert:\CurrentUser\My

You can validate the successful creation of your code signing certificate by examining the ‘EnhancedKeyUsageList’ attribute. This attribute helps ensure that the certificate is fit for its intended use.

How to Create Self-signed Certificate using PowerShell (6)

Similarly, you can create certificate for document encryption using the New-SelfSignedCertificate cmdlet. To create self-signed document encryption certificate, run the cmdlet with the ‘Type’ DocumentEncryptionCert. For example,

New-SelfSignedCertificate -Subject "DocEncryption" -CertStoreLocation Cert:\CurrentUser\My -Type DocumentEncryptionCert
How to Create Self-signed Certificate using PowerShell (7)

This example creates a document encryption certificate which is helpful to encrypt and decrypt documents.

Delete Self-Signed Certificate using PowerShell:

In some cases, admins want to remove certificates from certificate store. It can be done using the Remove-Item cmdlet.

Remove-Item -Path Cert:\CurrentUser\My\{PasteTheCertificateThumbprintHere} -DeleteKey 

With this method, you can delete expired certificates andcleanup certificate store.

In conclusion, self-signed certificates provide a cost-effective and secure solution for organizations without relying on external certificate authorities. Also, admins can automate PowerShell scripts using certificates. I hope our guide on creating and managing self-signed certificates simplifies your certificate management process. If you have any queries, you can reach us through the comment section.

Related Posts:

  • Connect to Microsoft Graph PowerShell using Certificate
  • How to Block Self-Service Purchase for Power…
  • Connect to Exchange Online with Certificate
  • Connect to SharePoint Online with Certificate
  • Disable Access to Exchange Online PowerShell - A…
  • ManageSelf-service Sign-up for Guests in Microsoft Entra
How to Create Self-signed Certificate using PowerShell (2024)

FAQs

How to Create Self-signed Certificate using PowerShell? ›

To create a self-signed certificate just use New-SelfSignedCertificate. It is really very simple! Once you have a self-signed certificate, you just use Set-Authinticode cmdlet to sign a script. BUT: for it to run, you have to trust the certificate on any machine that you want to run the script.

How do I create a PowerShell signing certificate? ›

The New-SelfSignedCertificate cmdlet creates a self-signed certificate for testing purposes. Using the CloneCert parameter, a test certificate can be created based on an existing certificate with all settings copied from the original certificate except for the public key.

What software is used to create self-signed certificates? ›

You can use PowerShell to generate self-signed certificates. The PKI Client can be used to generate a self-signed certificate. The certificate will be generated, but for the purposes of testing, should be placed in a cert store for testing in a browser.

How do I create credentials in PowerShell? ›

The Get-Credential cmdlet creates a credential object for a specified user name and password. You can use the credential object in security operations. The Get-Credential cmdlet prompts the user for a password or a user name and password. You can use the Message parameter to specify a customized message for the prompt.

Can I use a self-signed certificate in SSL? ›

Self-signed TLS/SSL certificates are safe in a testing environment, and you can use them while you are waiting for your certificates to be issued by a public CA. But, using them in a production environment will significantly decrease the traffic to your website or application and lead to a lack of trust from users.

What are examples of self-signed certificates? ›

For example, the Encrypting File System on Microsoft Windows issues a self-signed certificate on behalf of a user account to transparently encrypt and decrypt files on the fly. Another example is a root certificate, which is a form of self-signed certificate.

Can we create your own SSL certificate? ›

Technically, anyone can create their own SSL certificate by generating a public-private key pairing and including all the information mentioned above. Such certificates are called self-signed certificates because the digital signature used, instead of being from a CA, would be the website's own private key.

Can I create my own digital signature certificate? ›

Digital signatures are secure e-signatures backed by digital certificates. You can create a digital signature using Adobe's e-signature solution. Simply click the review link and opt to digitally sign. From there, select a signature source and name, then sign in to apply your digital signature.

How to export a certificate using PowerShell? ›

EXAMPLE 2 PS C:\>$cert = (Get-ChildItem -Path cert:\CurrentUser\My\EEDEF61D4FF6EDBAAD538BB08CCAADDC3EE28FF) PS C:\>Export-Certificate -Cert $cert -FilePath c:\certs\user. cer This example exports a certificate to the file system as a DER-encoded .

How to add a certificate from command prompt? ›

Open Command Prompt and type mmc and hit Enter to open MMC. Go to File menu, click Add/Remove Snap In, and add the Certificates snap-in for Local Computer. Once added, right-click in the middle window and select All Tasks > Import. Once imported, the certificate should show up under Local Computer and not Current User.

How to generate CSR using PowerShell? ›

Win+R >> powershell >> Enter. *Where script_file_name. ps1 is the script file and can have any suitable name. In the opened Notepad window, paste the whole code from here and save the file by pressing Ctrl+S or by using the File >> Save As menu.

How do I create a self-signed certificate for WSUS? ›

Creating a Self-Signed certificate

In the Ivanti Patch plugin, click on Settings in the ribbon bar. 2. Go to the WSUS Server Tab. In the section called 'WSUS signing certificate', click on the option for 'Create a self-signed certificate'.

Top Articles
Transportation Management
Crypto Gambling Regulations in the US, UK, and Canada
Dricxzyoki
Part time Jobs in El Paso; Texas that pay $15, $25, $30, $40, $50, $60 an hour online
Displays settings on Mac
When Is the Best Time To Buy an RV?
A.e.a.o.n.m.s
Mycarolinas Login
Cool Math Games Bucketball
Valentina Gonzalez Leak
Craigslist Alabama Montgomery
No Strings Attached 123Movies
Hijab Hookup Trendy
Summer Rae Boyfriend Love Island – Just Speak News
Quest Beyondtrustcloud.com
Espn Horse Racing Results
Daylight Matt And Kim Lyrics
Swgoh Blind Characters
Persona 5 Royal Fusion Calculator (Fusion list with guide)
Tripadvisor Napa Restaurants
Craigs List Tallahassee
Pawn Shop Moline Il
Xxn Abbreviation List 2017 Pdf
As families searched, a Texas medical school cut up their loved ones
Imagetrend Elite Delaware
Robert A McDougal: XPP Tutorial
Was heißt AMK? » Bedeutung und Herkunft des Ausdrucks
Fbsm Greenville Sc
Miss America Voy Board
What Is Xfinity and How Is It Different from Comcast?
Yoshidakins
Goodwill Thrift Store & Donation Center Marietta Photos
Personalised Handmade 50th, 60th, 70th, 80th Birthday Card, Sister, Mum, Friend | eBay
Craigslist List Albuquerque: Your Ultimate Guide to Buying, Selling, and Finding Everything - First Republic Craigslist
Daily Times-Advocate from Escondido, California
SF bay area cars & trucks "chevrolet 50" - craigslist
Сталь aisi 310s российский аналог
Panorama Charter Portal
2007 Jaguar XK Low Miles for sale - Palm Desert, CA - craigslist
Man Stuff Idaho
Discover Things To Do In Lubbock
Weekly Math Review Q2 7 Answer Key
18006548818
Phmc.myloancare.com
Hillsborough County Florida Recorder Of Deeds
Accident On 40 East Today
Dying Light Mother's Day Roof
Lesson 5 Homework 4.5 Answer Key
Suppress Spell Damage Poe
Julies Freebies Instant Win
211475039
ats: MODIFIED PETERBILT 389 [1.31.X] v update auf 1.48 Trucks Mod für American Truck Simulator
Latest Posts
Article information

Author: Sen. Ignacio Ratke

Last Updated:

Views: 6273

Rating: 4.6 / 5 (76 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Sen. Ignacio Ratke

Birthday: 1999-05-27

Address: Apt. 171 8116 Bailey Via, Roberthaven, GA 58289

Phone: +2585395768220

Job: Lead Liaison

Hobby: Lockpicking, LARPing, Lego building, Lapidary, Macrame, Book restoration, Bodybuilding

Introduction: My name is Sen. Ignacio Ratke, I am a adventurous, zealous, outstanding, agreeable, precious, excited, gifted person who loves writing and wants to share my knowledge and understanding with you.