r/exchangeserver • • 16h ago

Article Exchange Certificate Swap PowerShell - Github

https://github.com/LoneRiderOH/exchange-cert-swap.git

I hope guys/girls this will make you job easier.

A single-file PowerShell WPF GUI for replacing the public IIS/SMTP certificate on on-premises Exchange Server 2016, 2019 and Subscription Edition mailbox servers, using a PFX file or a free certificate from Let's Encrypt, ZeroSSL, Google Trust Services, SSL.com or Actalis. It covers the whole process: inventory, validation, import, enable, verification and safe removal of the old certificate. Dry run is on by default.

Features

  • Free certificates (optional): requests a certificate from Let's Encrypt, ZeroSSL, Google Trust Services, SSL.com or Actalis using the Posh-ACME module, and passes the resulting PFX straight to validation. Proof of domain ownership, chosen per request:

    • HTTP-01: the tool writes the challenge file into IIS on every selected server, so it works behind a load balancer. It checks that each server serves the file before the CA is asked to validate.
    • DNS-01 manual: the tool shows the _acme-challenge TXT records to create, then checks public DNS before continuing. Supports wildcards.
    • DNS-01 automatic via Cloudflare: built-in option for domains hosted on Cloudflare DNS. You paste a scoped API token, and the tool tests it, creates and removes the TXT records itself, and can remember the token, encrypted for your Windows user. It also detects when your names are on Cloudflare DNS.
    • DNS-01 automatic via other DNS hosts: uses any of Posh-ACME's ~90 DNS provider plugins (Route 53, Azure DNS, GoDaddy and more).
  • Inventory: lists every Exchange certificate on all selected mailbox servers and marks the Auth (OAuth) and internal transport certificates.
  • Validation before changes (read-only):

    • the PFX contains a private key, is in its validity period and has the Server Authentication EKU
    • the chain builds to a trusted root
    • every InternalUrl/ExternalUrl on the OWA, ECP, EWS, OAB, ActiveSync and MAPI virtual directories, plus the Autodiscover SCP, is covered by the certificate's SANs (wildcards are handled correctly)
    • lists Send and Receive connectors whose TlsCertificateName still points to the old certificate
  • Import to multiple servers: imports the same PFX on every selected server with Import-ExchangeCertificate -FileData, so the tool doesn't need to be run on each server.
  • SMTP connectors: updates Send and Receive connectors whose TlsCertificateName points to the old certificate, such as the hybrid Outbound to Office 365 and Default Frontend connectors set by the HCW. It can also pin the new certificate on the Default Frontend connector (port 25), so internet senders get the public certificate on STARTTLS instead of the self-signed one. The connector FQDN is never changed, and rollback commands are logged.
  • Enable for IIS and SMTP: if Enable-ExchangeCertificate -Force replaces the internal transport certificate, the tool restores the previous one unless you choose otherwise.
  • Verification on the network: opens a real TLS connection to each server on port 443 and compares the served thumbprint with the new certificate. It also checks SMTP port 25 with STARTTLS (for information only) and any extra endpoints you list, such as a load balancer or public name.
  • Safe removal of the old certificate: a certificate is removed only if: You confirm each removal.

    • its server passed verification
    • it is not the Auth or internal transport certificate
    • it is no longer bound to IIS
    • no connector points to it
  • Dry run by default: every command is logged instead of being run. You turn Dry run off on purpose, and the header switches to red LIVE MODE.
  • Full log: each run writes logs\CertSwap_<timestamp>.log next to the script. PFX passwords are never logged.
  • No private key is written to the machine that runs the tool: the PFX is opened with EphemeralKeySet, so its key stays in memory. It never goes into a Windows key store or onto a smart card or hardware token. The key is installed only on the Exchange servers, through Import-ExchangeCertificate.
30 Upvotes

11 comments sorted by

2

u/wichets 15h ago

Very Cool.

1

u/Interesting-Pea-6558 7h ago

It was my pleasure

2

u/joshfsr 10h ago

Awesome! Thank you!

2

u/Interesting-Pea-6558 7h ago

It was my pleasure

1

u/rocuspeter 10h ago

Thank you

2

u/Interesting-Pea-6558 7h ago

It was my pleasure

1

u/intmanofawesome 9h ago

Thank you, this was on my hit list for this week to come up with the proper process and script to use and update LE certain on our exchange servers.

2

u/Interesting-Pea-6558 7h ago

It was my pleasure

3

u/stkyrice 7h ago

Claude code design for sure.

1

u/MikeoFree 15h ago

3

u/RemindMeBot 15h ago

I will be messaging you in 7 days on 2026-11-29 07:46:23 UTC to remind you of this link

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.


InfoCustomYour RemindersFeedback