How to Export a certificate from a certificate store using PowerShell?


To export or download a certificate from the certificate store using PowerShell, we need to use the command Export-Certificate.

First, you need to get the certificate details from the store. If you know the thumbprint, you can directly get the certificate details using the thumbprint and then use that details to export the certificate.

Example

$cert = (Get-ChildItem  Cert:\LocalMachine\My\43E6035D120EBE9ECE8100E8F38B85A9F)
Export-Certificate -Cert $cert -Type CERT -FilePath C:\Temp\Mycert.cer

In the above example, we are exporting the certificate from the LocalMachine -> Personal Store. You can choose a different path. Here, the certificate would be exported to the C:\temp\MyCert.cer.

 You can use the different types like P7B, SST to export the certificate. Alternatively, you can use the below command.

Syntax

Get-ChildItem Cert:\LocalMachine\My\43E6035D120EBE9ECE8100E8F38B85A9F1C1140F `
   | Export-Certificate -Type cer -FilePath C:\Temp
ewcert.cer -Force

If you don't know the certificate thumbprint then you can use any of the certificate's unique properties like Subject, FriendlyName, etc to retrieve the details.  For example,

Example

Get-ChildItem Cert:\LocalMachine\My\  `
   | where{$_.FriendlyName -eq "mysitecert"}  `
   | Export-Certificate -Type cer -FilePath C:\Temp
ewcert.cer -Force

Updated on: 18-Mar-2021

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements