Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security & DevOps Insights

  • Home
  • About
  • Advertise With US
  • Reviews
  • Contact
  • Toggle search form
Home » Scripts » Create a self-signed certificate and export it in PFX format via PowerShell [Part 1]
  • windows deployment services imagen destacada blog redigit
    How to create a capture image on Windows Deployment Services Windows Server
  • Leave Slack
    How to remove a user from a Slack Channel JIRA|Confluence|Apps
  • KMS server setup
    How to set up and configure the Key Management System (KMS) Windows Server
  • firewall windows 1
    Periodic Scanning: How to schedule Windows Defender Antivirus to scan on Windows Windows
  • Account restrictions are preventing this user from signing in
    Resolve Account restrictions are preventing this user from signing in: User Account Password has expired Windows
  • Screenshot 2022 04 02 at 23.05.24
    How to apply Windows Updates with PowerShell Windows
  • BitLocker selfservice or helpdesk recovery
    Force BitLocker Recovery: Perform BitLocker Recovery via the Self-Service Portal and Helpdesk Network | Monitoring
  • powershell
    How to install and uninstall PowerShell on macOS via Homebrew Mac

Create a self-signed certificate and export it in PFX format via PowerShell [Part 1]

Posted on 09/04/202025/03/2024 Christian By Christian 2 Comments on Create a self-signed certificate and export it in PFX format via PowerShell [Part 1]

A self-signed certificate is a certificate that is signed by the person or organization creating it rather than a trusted certificate authority. In this article, we shall discuss how to create a self-signed certificate and export it in PFX format via PowerShell [Part 1]. Please see how to Delete Quick Heal Anti-virus cfrbackup folder, and Generate a self-signed SSL certificate: How to enable LDAP over SSL with a self-signed certificate. When using a self-signed certificate, there is no chain of trust. The certificate has signed itself.

The web browser will then issue a warning, telling you that the website certificate cannot be verified. See the following interesting guides on how to import a certificate into the Trusted Root and Personal file certificate store, and how to request a certificate signing request in Windows using Microsoft Management Console.

Guidance on Self-signed certificate!

Generally, a self-signed certificate is no longer recommended in an enterprise environment. But very vital in a test scenario where a certificate is a requirement for testing. This saves time and resources by buying a certificate or deploying your own Public Key Infrastructure (PKI) environment.

Wish to see a different method on how to accomplish this task, kindly see “how to generate a self-signed certificate and export in PFX format via PowerShell [Part 2]“.

Note: This can be generated using MMC and IIS (Internet Information Services). I will be demonstrating these steps in a later post.

Create a self-signed certificate in PowerShell

Steps: Ensure to run PowerShell with administrator privileges. Learn how to export a certificate in PFX format in Windows.

1. Run the following command below. The New-SelfSignedCertificate cmdlet as shown below to add a certificate to the local store on your PC, replacing the fully qualified domain name (FQDN).

$cert = New-SelfSignedCertificate -certstorelocation cert:\localmachine\my -dnsname techdirect.local

Export Certificate in PFX format

2. In this step, we will export the self-signed certificate. We will need to create a password as shown below to accomplish this step

$pwd = ConvertTo-SecureString -String ‘passw0rd!’ -Force -AsPlainText

3. We will have to export the self-signed certificate using the Export-PfxCertificate cmdlet as shown below.

The password ($pwd) created will be used to create an additional string ($path), which specifies the path to the certificate created with the New-SelfSignedCertificate cmdlet.

$path = 'cert:\localMachine\my\' + $cert.thumbprint Export-PfxCertificate -cert $path -FilePath c:\cert.pfx -Password $pwd

Note: The c:\temp directory, or whatever directory you specify in the -FilePath parameter, must already exist. You can now import the cert.pfx file to install the certificate.

Note: The few lines of codes can be combined together as shown below to create and store a self-signed certificate in the Windows Certificate Store. The last line (Export-Pfx Certificate) will export the certificate.

$cert = New-SelfSignedCertificate -certstorelocation cert:\localmachine\my -dnsname techdirect.local
$pwd = ConvertTo-SecureString -String ‘passw0rd!’ -Force -AsPlainText
$path = 'cert:\localMachine\my\' + $cert.thumbprint 
Export-PfxCertificate -cert $path -FilePath c:\cert.pfx -Password $pwd

Please see how to Install Windows Admin Center in an unattended mode using a self-signed certificate, and

I hope you found this blog post helpful on how to create a self-signed certificate and export it in PFX format via PowerShell [Part 1]. If you have any questions, please let me know in the comment session.

Rate this post

Thank you for reading this post. Kindly share it with others.

  • Share on X (Opens in new window) X
  • Share on Reddit (Opens in new window) Reddit
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Facebook (Opens in new window) Facebook
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Telegram (Opens in new window) Telegram
  • Share on WhatsApp (Opens in new window) WhatsApp
  • Share on Pocket (Opens in new window) Pocket
  • Share on Mastodon (Opens in new window) Mastodon
  • Share on Bluesky (Opens in new window) Bluesky
  • Share on Threads (Opens in new window) Threads
  • Share on Nextdoor (Opens in new window) Nextdoor
Scripts Tags:Cert, Certificates, Microsoft Windows, PowerShell, Windows 10

Post navigation

Previous Post: How to create a KDS root key using PowerShell
Next Post: How to install and Update Azure PowerShell on your Windows PC

Related Posts

  • Azure App Service
    How to Restore Deleted Azure App Service Using PowerShell Automation
  • AzureCloudShell
    Provisioning Azure Resources using Azure Az PowerShell Cmdlet from Cloud Shell AWS/Azure/OpenShift
  • CI With GitLab 1
    Build Docker Images with GitLab CI Automation
  • powershell01
    How to create a KDS root key using PowerShell Scripts
  • Chocolatey Packages
    Create Chocolatey Package: Upgrade Software with Chocolatey Scripts
  • powershell01
    WinRM and PSRemoting: Configure servers for remote access Scripts

More Related Articles

Azure App Service How to Restore Deleted Azure App Service Using PowerShell Automation
AzureCloudShell Provisioning Azure Resources using Azure Az PowerShell Cmdlet from Cloud Shell AWS/Azure/OpenShift
CI With GitLab 1 Build Docker Images with GitLab CI Automation
powershell01 How to create a KDS root key using PowerShell Scripts
Chocolatey Packages Create Chocolatey Package: Upgrade Software with Chocolatey Scripts
powershell01 WinRM and PSRemoting: Configure servers for remote access Scripts

Comments (2) on “Create a self-signed certificate and export it in PFX format via PowerShell [Part 1]”

  1. Avatar photo warda says:
    30/12/2020 at 12:35 AM

    hi I am getting this error in power shell, I dont understand how do you open it in administrator account. I am doing this from my personal laptop

    PS C:\Users\Hareem> $cert = New-SelfSignedCertificate -certstorelocation cert:\localmachine\my -dnsname techdirect.local
    >>
    New-SelfSignedCertificate : CertEnroll::CX509Enrollment::_CreateRequest: Access denied. 0x80090010 (-2146893808
    NTE_PERM)
    At line:1 char:9
    + $cert = New-SelfSignedCertificate -certstorelocation cert:\localmachi …
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo     : NotSpecified: (:) [New-SelfSignedCertificate], Exception
      + FullyQualifiedErrorId : System.Exception,Microsoft.CertificateServices.Commands.NewSelfSignedCertificateCommand

    Log in to Reply
    1. chris Christian says:
      30/12/2020 at 12:48 AM

      Hi Warda, search for PowerShell from the Windows Search as attached.

      • You have to right-click on it and select run as Administrator
      Log in to Reply

Leave a Reply Cancel reply

You must be logged in to post a comment.

Microsoft MVP

VEEAMLEGEND

vexpert-badge-stars-5

Virtual Background

GoogleNews

Categories

veeaam100

sysadmin top30a

  • windows deployment services imagen destacada blog redigit
    How to create a capture image on Windows Deployment Services Windows Server
  • Leave Slack
    How to remove a user from a Slack Channel JIRA|Confluence|Apps
  • KMS server setup
    How to set up and configure the Key Management System (KMS) Windows Server
  • firewall windows 1
    Periodic Scanning: How to schedule Windows Defender Antivirus to scan on Windows Windows
  • Account restrictions are preventing this user from signing in
    Resolve Account restrictions are preventing this user from signing in: User Account Password has expired Windows
  • Screenshot 2022 04 02 at 23.05.24
    How to apply Windows Updates with PowerShell Windows
  • BitLocker selfservice or helpdesk recovery
    Force BitLocker Recovery: Perform BitLocker Recovery via the Self-Service Portal and Helpdesk Network | Monitoring
  • powershell
    How to install and uninstall PowerShell on macOS via Homebrew Mac

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,825 other subscribers
  • RSS - Posts
  • RSS - Comments
  • About
  • Authors
  • Write for us
  • Advertise with us
  • General Terms and Conditions
  • Privacy policy
  • Feedly
  • Telegram
  • Youtube
  • Facebook
  • Instagram
  • LinkedIn
  • Tumblr
  • Pinterest
  • Twitter
  • mastodon

Tags

AWS Azure Bitlocker Microsoft Windows PowerShell WDS Windows 10 Windows 11 Windows Deployment Services Windows Server 2016

Copyright © 2025 TechDirectArchive

 

Loading Comments...
 

You must be logged in to post a comment.