← Files

Import-CaCertificates#


1. Overview#

Import-CaCertificates is a professional PowerShell utility designed to automate the process of downloading and importing Root and Intermediate CA certificates into the Windows Certificate Store. This is particularly useful for servers behind firewalls, automated deployments, and fixing "Unknown CA" errors in mail servers like hMailServer and Exim.

Primary Purpose#

The script ensures that your Windows environment trusts the necessary Certificate Authorities by:


2. Key Features#


3. System Requirements#


4. Quick Start Guide#

Step 1: Download the script#

Invoke-WebRequest -Uri "https://raw.githubusercontent.com/paulmann/Import-CaCertificates/main/Import-CaCertificates.ps1" -OutFile "Import-CaCertificates.ps1"

Step 2: Run as Administrator#

Open PowerShell as Administrator and execute:

.\Import-CaCertificates.ps1 -RootUrl "https://example.com/root.crt" -IntermediateUrl "https://example.com/intermediate.crt"

5. Installation & Setup#

  1. Clone or download this repository.

  2. Ensure Set-ExecutionPolicy RemoteSigned is configured for your session.

  3. Place the script in your tools directory (e.g., C:\Scripts\).


6. How It Works#

The script follows a secure execution flow:

  1. Privilege Check: Validates that the script is running with administrative rights.

  2. Environment Setup: Creates a temporary directory for certificate processing.

  3. Download Phase: Fetches certificates using Invoke-WebRequest.

  4. Import Phase:

    • Root certificates -> LocalMachine\Root

    • Intermediate certificates -> LocalMachine\CA

  5. Cleanup: Deletes temporary files and objects.


7. Let's Encrypt Integration Guide#

Let's Encrypt certificates often require specific Root and Intermediate CAs to be trusted by Windows services (like hMailServer or Exim).

7.1 Typical Commands (Let's Encrypt ISRG Root X1)#

To trust the standard Let's Encrypt chain:

.\Import-CaCertificates.ps1 `
    -RootUrl "https://letsencrypt.org/certs/isrgrootx1.pem" `
    -IntermediateUrl "https://letsencrypt.org/certs/lets-encrypt-r3.pem"

7.2 Advanced / Additional Commands (Cross-Signed Chains)#

For environments requiring the older DST Root CA X3 cross-sign (for legacy compatibility):

.\Import-CaCertificates.ps1 `
    -RootUrl "https://letsencrypt.org/certs/isrg-root-x2.pem" `
    -IntermediateUrl "https://letsencrypt.org/certs/lets-encrypt-e1.pem" `
    -Force

8. Usage Examples#

Import only a Root CA#

.\Import-CaCertificates.ps1 -RootUrl "http://cacerts.digicert.com/DigiCertGlobalRootG2.crt"

Import with temporary file retention (for debugging)#

.\Import-CaCertificates.ps1 -RootUrl "..." -KeepFiles

9. Parameters Reference#

Parameter Type Required Description
RootUrl String Yes URL to the Root CA certificate file (.crt, .cer, .pem).
IntermediateUrl String No URL to the Intermediate CA certificate file.
Force Switch No Force re-import of certificates even if already present.
KeepFiles Switch No Do not delete temporary files after completion.

10. Troubleshooting#


11. License & Acknowledgments#

License#

This project is licensed under the PolyForm Noncommercial License 1.0.0.

Copyright © 2025 Mikhail Deynekin.
Author: Mikhail Deynekin


⭐ Support the Project#

If this tool helped you resolve certificate issues, please give it a star on GitHub!