There are a couple of ways to export a certificate from a Windows server. The most common way is to export a certificate from the ‘MMC’ console. If you want to know how to export a certificate from MMC, you can see this post. However, we are going to show you an alternate way of exporting a certificate from PowerShell commands. In this post, we have covered how to export a certificate from PowerShell in CER, PFX, P7B, and SST formats.
You should bear in mind that PFX certificates are always encrypted since they have a private key in the archive. It is mandatory to set a password to export a certificate in PFX format. Syntax of the command to export a certificate in PFX is:
Syntax:
$mypwd = ConvertTo-SecureString -String "<PASSWORD>" -Force -AsPlainText
Get-ChildItem -Path Cert:\<PATH>\ | where{$_.Thumbprint -eq "<THUMBPRINT OF THE CERTIFICATE>"} | Export-PfxCertificate -FilePath <PATH WHERE THE CERTIFICATE IS SAVED> -Password $mypwd
In this example, the first line of command signifies setting a password “1234” as a string text. Execute this command in Windows PowerShell to export a certificate with a Private Key which includes the chain of Intermediate and root CA certificate
Example:
$mypwd = ConvertTo-SecureString -String "1234" -Force -AsPlainText
Get-ChildItem -Path Cert:\LocalMachine\My\ | where{$_.Thumbprint -eq "4eeee9dca7dd5ccf70e47e46ac1128ddddbbb321"} | Export-PfxCertificate -FilePath C:\Temp\mypfx.pfx -Password $mypwd
It is simple to export a certificate from PowerShell in CER format comparatively exporting the same certificate in PFX format. In this export, it is good to have thumbprint of the certificate. In case if you don’t have the thumbprint, you can use any unique properties of a certificate to export. Syntax looks like this:
Syntax:
Get-ChildItem -Path Cert:<PATH> | where{$_.FriendlyName -eq "<NAME>"} | Export-Certificate -Type cer -FilePath <PATH WHERE THE CERTIFICATE IS SAVED> -Force
Example:
In this sample, the certificate has been exported using FriendlyName as a unique property instead of the Thumbprint.
Get-ChildItem -Path Cert:\LocalMachine\My\ | where{$_.FriendlyName -eq "www.thesecmaster.local"} | Export-Certificate -Type cer -FilePath C:\Temp\newcert.cer -Force
P7B is a certificate archive with chain certificates. The command and the procedure to export P7B certificate is more or less similar to CER certificate. You need to change the certificate type during the export. That’s all.
Syntax:
Get-ChildItem -Path Cert:<PATH> | where{$_.Thumbprint -eq "<THUMBPRINT>"} | Export-Certificate -Type p7b -FilePath <PATH WHERE THE CERTIFICATE IS SAVED> -Force
Example:
Get-ChildItem -Path Cert:\LocalMachine\My\ | where{$_.Thumbprint -eq "4eeee9dca7dd5ccf70e47e46ac1128ddddbbb321"} | Export-Certificate -Type p7b -FilePath C:\Temp\newcer.p7b -Force
It is similar to export a certificate in SST as CER. You can see the syntax and an example here below.
Syntax:
Get-ChildItem -Path Cert:<CERTIFICATE> | Export-Certificate -Type SST -FilePath <PATH WHERE THE CERTIFICATE IS SAVED> -Force
Example:
Get-ChildItem -Path cert:\localMachine\my\4eeee9dca7dd5ccf70e47e46ac1128ddddbbb321 | Export-Certificate -Type SST -FilePath C:\Temp\newcer.sst -Force
Thumbprint plays a vital role in security. It is the hash or the signature of the certificate. The procedure is simple to get the thumbprint of a certificate. First, we will show you how to get the thumbprint of a certificate using the PowerShell command then we will show you the GUI method.
Issue this command to retrieve the thumbprint of your certificate:
$cert = Get-ChildItem Cert:\LocalMachine\My `
| where{$_.Subject -eq "CN=mysite.local"}
Issue this command to retrieve the thumbprint of all the certificates in the personal store:
Get-ChildItem Cert:\LocalMachine\My\
As a bonus tip, we will show you how and where to find the thumbprint of a certificate. The procedure is simple. Open the certificate in Windows, go to Details tab then select the Thumbprint attribute. Or you can use any CLI tools like OpenSSL to view the certificate in CLI.
Open IIS website in any browser –> Click on ‘View Certificate‘
2. In certificate window –> click on ‘Details‘ tab –> select ‘Thumbprint‘ –> Thumbprint of a given certificate is
‘4eeee9dca7dd5ccf70e47e46ac1128ddddbbb321′
We hope this post will show you how to export a certificate from PowerShell in CER, PFX, P7B, and SST formats. Please share this post and help to secure the digital world. Visit our social media page on Facebook, LinkedIn, Twitter, Telegram, Tumblr, Medium & Instagram, and subscribe to receive updates like this.
You may also like these articles:
Arun KL is a cybersecurity professional with 15+ years of experience in IT infrastructure, cloud security, vulnerability management, Penetration Testing, security operations, and incident response. He is adept at designing and implementing robust security solutions to safeguard systems and data. Arun holds multiple industry certifications including CCNA, CCNA Security, RHCE, CEH, and AWS Security.
“Knowledge Arsenal: Empowering Your Security Journey through Continuous Learning”
"Cybersecurity All-in-One For Dummies" offers a comprehensive guide to securing personal and business digital assets from cyber threats, with actionable insights from industry experts.
BurpGPT is a cutting-edge Burp Suite extension that harnesses the power of OpenAI's language models to revolutionize web application security testing. With customizable prompts and advanced AI capabilities, BurpGPT enables security professionals to uncover bespoke vulnerabilities, streamline assessments, and stay ahead of evolving threats.
PentestGPT, developed by Gelei Deng and team, revolutionizes penetration testing by harnessing AI power. Leveraging OpenAI's GPT-4, it automates and streamlines the process, making it efficient and accessible. With advanced features and interactive guidance, PentestGPT empowers testers to identify vulnerabilities effectively, representing a significant leap in cybersecurity.
Tenable BurpGPT is a powerful Burp Suite extension that leverages OpenAI's advanced language models to analyze HTTP traffic and identify potential security risks. By automating vulnerability detection and providing AI-generated insights, BurpGPT dramatically reduces manual testing efforts for security researchers, developers, and pentesters.
Microsoft Security Copilot is a revolutionary AI-powered security solution that empowers cybersecurity professionals to identify and address potential breaches effectively. By harnessing advanced technologies like OpenAI's GPT-4 and Microsoft's extensive threat intelligence, Security Copilot streamlines threat detection and response, enabling defenders to operate at machine speed and scale.