Export Certificate - PowerShell


Overview

The Export-Certificate cmdlet exports a certificate from the local computer’s certificate store to a specified file. This allows you to save and share certificates for use in other applications or systems.

Syntax

Export-Certificate [-FilePath] <String> [-Type] <String> [-Format] <String> [-Password] <String> [-IncludePrivateKey]
[-FriendlyName] <String> [-Thumbprint] <String> [-Subject] <String> [-Issuer] <String> [-FindType] <String>
[-Location] <String> [-StoreName] <String>

Options/Flags

  • -FilePath: Specifies the path and file name where the certificate should be exported to.
  • -Type: Specifies the type of certificate to export. Valid values are: Authenticode, Disallowed, KeyStorage, Root, TrustedPublisher, TrustedRoot.
  • -Format: Specifies the format of the exported certificate. Valid values are: Base64, Binary, Pfx.
  • -Password: Specifies the password to use to protect the exported certificate.
  • -IncludePrivateKey: Exports the private key along with the certificate.
  • -FriendlyName: Exports the certificate with the specified friendly name.
  • -Thumbprint: Exports the certificate with the specified thumbprint.
  • -Subject: Exports the certificate with the specified subject.
  • -Issuer: Exports the certificate with the specified issuer.
  • -FindType: Specifies the type of search to use when finding the certificate. Valid values are: FindBySubject, FindByThumbprint, FindByFriendlyName, FindByIssuer, FindBySubjectDistinguishedName, FindByIssuerDistinguishedName, FindByExtension.
  • -Location: Specifies the location of the certificate store to search for the certificate. Valid values are: CurrentUser, LocalMachine, Enterprise.
  • -StoreName: Specifies the name of the certificate store to search for the certificate.

Examples

Example 1: Export a certificate to a file using the default settings

Export-Certificate -FilePath "C:\path\to\certificate.cer"

Example 2: Export a certificate in PFX format with a password

Export-Certificate -FilePath "C:\path\to\certificate.pfx" -Format Pfx -Password "mypassword"

Example 3: Export the private key along with the certificate

Export-Certificate -FilePath "C:\path\to\certificate.pfx" -IncludePrivateKey -Password "mypassword"

Common Issues

If you encounter an error when exporting a certificate, check the following:

  • Ensure that the certificate is installed on the local computer.
  • Verify that you have the necessary permissions to export the certificate.
  • Make sure that the file path specified for the exported certificate is valid.

Integration

The Export-Certificate cmdlet can be combined with other PowerShell commands to automate certificate management tasks. For example, you can use the Get-Certificate cmdlet to find certificates and then use the Export-Certificate cmdlet to export them to a file.

  • Get-Certificate
  • Install-Certificate
  • Remove-Certificate