Every Host Expires the Same Week: ESXi Certificate Renewal with PowerCLI, Rehearsed Before the Window

The customer in this story is invented. Call it a Fortune 500 retailer: two data centers, a little over three hundred ESXi hosts on vSphere 8.0 Update 3, and a hardware refresh five winters ago that put most of them into vCenter within the same few weeks. I role-played the engagement instead of waiting for it, because a tool that replaces the certificate every host presents to vCenter should not meet a production fleet for the first time on the night it is needed.

Everything else here is real. The failure modes are Broadcom’s own knowledge base articles. The tool is a PowerShell script in the repository at the end. And every block of output below came from that script, run against a vCenter simulator I extended until it failed the way those articles say production fails. This is the estate, the rehearsal, what the script refused to do, and the bugs the rehearsal found before a customer could.

Every Host Expires the Same Week

When a host is added to vCenter in the default certificate mode, vCenter’s own certificate authority, VMCA, issues the host’s certificate, and that certificate is good for 1,825 days: five years from the afternoon someone clicked Add Host. A host that stays connected keeps it until someone renews it. vCenter raises an event at 240 days and a red ESXi Host Certificate Status alarm at 30.

So a fleet built in one refresh expires in one wave. It is November 2026, the retailer’s hosts went in between November 2021 and January 2022, and forty of them turned red in the same week with the rest of two data centers lined up behind them. The vSphere Client’s answer is a Renew button, one host at a time, and three cases where clicking it is the wrong thing to do while nothing on the screen says so:

  • The host is in maintenance mode. The renewal task finishes and the certificate does not change (KB 390133). The alarm is still there in the morning.
  • VMCA’s own root certificate ends first. A certificate authority cannot issue past its own end date, so a renewed host certificate ends when the root does. On a vCenter that has been upgraded in place for ten years, that date is close: Renew completes and the expiry date does not move (KB 416914, KB 419417).
  • The host carries a certificate from the company CA. Somebody did that work on purpose, and the documentation covers what happens next in one sentence: if your environment is in VMCA mode, and you refresh the certificates from the vSphere Client, any existing certificates are replaced with certificates that are signed by VMCA.

None of the three is a failed task. That is the part that costs a night: the work reports success, and the only way to know is to read the certificate back.

The Estate, in Nine Hosts

Three hundred hosts do not fit in a simulator and do not need to. What a fleet that size contains is cases, and the rehearsal has one host for each:

Host Stands for
esx01 a host that is simply due: 20 days left
esx02 hardware replaced last year, 900 days left, to be left alone
esx03 due, and in maintenance mode waiting on a part
esx04 due, and one update behind, on ESXi 8.0 Update 2
esx05 due, and on a certificate from the company CA that someone installed by hand
esx06 due, and disconnected
esx07, esx09 not due yet at 40 and 50 days; esx07 is already on ESXi 9
esx08 a host outside any cluster, 700 days left

The simulator is govmomi‘s vcsim, which answers the vSphere API well enough for PowerCLI to log in and list hosts, plus the certificate calls it does not implement. I wrote those to behave the way the API reference and the knowledge base describe: a renewal in maintenance mode completes and changes nothing, a VMCA certificate is cut to the root’s end date, a host reads Not responding for a few seconds after a renewal (KB 420313), a host serves its old certificate on port 443 until its services are told to pick up the new one, and a host that is handed a certificate vCenter does not trust disconnects. Every host has a name and an address and answers on port 443, in a network namespace of its own on one Linux box, and the script runs against it under PowerShell 7 with PowerCLI, logging in the way an administrator would. It is in the repository under bench/, with the 68 checks it runs.

The Plan Comes First

The script is Update-EsxiCertificate.ps1. It logs in through PowerCLI, reads every host’s certificate from vCenter and prints what it would do. Without -Commit that is all it does:

.\Update-EsxiCertificate.ps1 -Server vcsa01.example.com -Credential (Get-Credential)

esxi-cert-renew 1.0.0  vCenter vcsa01.example.com (8.0.3), certificate mode vmca
renew certificates that expire within 30 days; plan only: nothing is changed (add -Commit)

HOST               CLUSTER  EXPIRES      DAYS  ISSUER                PLAN
esx01.example.com  cl01     2026-12-07     20  VMCA                  WOULD renew through VMCA: 20 days left
esx02.example.com  cl01     2029-05-05    900  VMCA                  ok, 900 days left
esx03.example.com  cl01     2026-11-27     10  VMCA                  SKIP: 10 days left, but in maintenance mode, where vCenter does not renew: exit maintenance mode and run again
esx04.example.com  cl01     2026-12-02     15  VMCA                  WOULD renew through VMCA: 15 days left
esx05.example.com  cl02     2026-12-12     25  Example Issuing CA 1  SKIP: 25 days left, but issued by 'Example Issuing CA 1', not VMCA, and a renewal in vmca mode would replace it. To keep CA certificates use custom mode; if that is your VMCA, add -VmcaIssuer (README)
esx06.example.com  cl02     2026-11-22      5  VMCA                  SKIP: not connected (disconnected): reconnect it first
esx07.example.com  cl02     2026-12-27     40  VMCA                  ok, 40 days left
esx09.example.com  cl02     2027-01-06     50  VMCA                  ok, 50 days left
esx08.example.com           2028-10-17    700  VMCA                  ok, 700 days left

2 host(s) to change. Run again with -Commit.

Two hosts to renew out of nine, and three it will not touch. The maintenance-mode host is the first of the silent cases, caught before the task that would have reported success. The disconnected host needs a person. The one with the company CA’s certificate is the third silent case, and the line names the issuer, because if that issuer is in fact a VMCA someone renamed, -VmcaIssuer says so and the host is renewed like the others. The default window is the 30 days at which vCenter turns the alarm red; -Days 90 widens it, and -All ignores it.

One Host at a Time

.\Update-EsxiCertificate.ps1 -Server vcsa01.example.com -Cluster cl01 -Commit

  esx01.example.com: refreshing CA certificates
  esx01.example.com: renewing through VMCA
  esx01.example.com: done: expires 2031-11-16, issued by VMCA; port 443 serves it
  esx04.example.com: refreshing CA certificates
  esx04.example.com: renewing through VMCA
  esx04.example.com: done: expires 2031-11-16, issued by VMCA; port 443 serves it

2 certificate(s) replaced and verified.

Each host is read again before anything is asked of it: still connected, still out of maintenance mode, still on the certificate the plan saw. Then the script refreshes the host’s CA certificates, which the vSphere Client’s Renew does implicitly (KB 426775), and renews through vCenter with the same API call as the Renew button.

Done is three separate facts. The host is connected again: the script waits out the Not responding moment for up to five minutes instead of reporting it. vCenter shows a certificate that expires later than the one it replaced. And port 443 on the host serves that certificate, read from the machine the script runs on with a plain TLS handshake. If the machine cannot reach the host, the line says port 443 not reachable from here instead of claiming a check it did not make. The run stops at the first host that fails any of the three, with the rest of the list untouched, and exits 1.

The next plan reads the way it should:

HOST               CLUSTER  EXPIRES      DAYS  ISSUER                PLAN
esx01.example.com  cl01     2031-11-16   1824  VMCA                  ok, 1824 days left
esx04.example.com  cl01     2031-11-16   1824  VMCA                  ok, 1824 days left

And because an auditor will ask, -PassThru returns one object per host, which is one pipe away from a record of every certificate in the vCenter:

.\Update-EsxiCertificate.ps1 -Server vcsa01.example.com -PassThru | Select-Object Host, Cluster, Expires, Issuer, Result | Export-Csv esxi-certs.csv -NoTypeInformation

"Host","Cluster","Expires","Issuer","Result"
"esx01.example.com","cl01","2031-11-16","VMCA","ok"
"esx02.example.com","cl01","2029-05-05","VMCA","ok"
"esx03.example.com","cl01","2026-11-27","VMCA","skipped"
"esx04.example.com","cl01","2031-11-16","VMCA","ok"
"esx05.example.com","cl02","2026-12-12","Example Issuing CA 1","skipped"
"esx06.example.com","cl02","2026-11-22","VMCA","skipped"
"esx07.example.com","cl02","2026-12-27","VMCA","ok"
"esx09.example.com","cl02","2027-01-06","VMCA","ok"
"esx08.example.com","","2028-10-17","VMCA","ok"

The Renewal That Could Not Help

The retailer’s second vCenter is the older one, upgraded in place since 2016, and its VMCA root certificate was minted with it: ten years, ending this December. Same fleet, same command, and the plan has one more thing to say:

HOST               CLUSTER  EXPIRES      DAYS  ISSUER                PLAN
esx01.example.com  cl01     2026-12-07     20  VMCA                  WOULD renew through VMCA: 20 days left; but VMCA's CA certificate on its list expires 2026-12-07 and a renewal cannot outlast it: -Commit refreshes the list from vCenter and renews only if that helps (KB 419417)
esx04.example.com  cl01     2026-12-02     15  VMCA                  WOULD renew through VMCA: 15 days left; but VMCA's CA certificate on its list expires 2026-12-07 and a renewal cannot outlast it: -Commit refreshes the list from vCenter and renews only if that helps (KB 419417)

A renewal here would run, complete, and hand esx01 a certificate that ends on the same day as the one it has. So the script does not start one. With -Commit it first refreshes the host’s CA list from vCenter, in case the root has been replaced since the host last heard, reads the end date of VMCA’s certificate from that list, and refuses:

  esx01.example.com: refreshing CA certificates
  esx01.example.com: FAILED: nothing was changed: VMCA's CA certificate expires 2026-12-07 and a renewal cannot outlast it. Renew the VMCA root first (KB 419417)

Stopped at the failure. 1 host(s) not attempted.

The fix is one layer up and is not this script’s to make: replace the VMCA root first (KB 419417 walks through it with Broadcom’s vCert utility), then renew the hosts. The rule the script applies is that a renewal has to get the host out of the window that made it due. One that buys five days is refused the same way.

Act Two: The Company CA

The second half of the engagement is the one a security team starts. The standard says every management endpoint presents a certificate from the company’s own CA, and VMCA is not that. vCenter has a mode for it, custom, and since 8.0 Update 3 hosts can be moved to it without a reboot: the host writes a certificate signing request and keeps the private key, the CA signs the request, and the signed certificate is imported.

Two things come first, and the order matters. vCenter has to trust the CA before any host presents a certificate from it, or the host disconnects the moment it does. Then vCenter is told to leave host certificates alone:

Add-VITrustedCertificate -VCenterOnly -PemCertificateOrChain (Get-Content .\ca-chain.pem -Raw)
Get-AdvancedSetting -Entity $global:DefaultVIServer -Name vpxd.certmgmt.mode | Set-AdvancedSetting -Value custom -Confirm:$false

The script does neither. Both are decisions about who vouches for the hosts, and the simulator starts this scene with both made. After that a round is the same command run twice, with a folder in between:

.\Update-EsxiCertificate.ps1 -Server vcsa01.example.com -CertFolder .\certs -Days 90 `
    -Subject 'C=US, ST=Virginia, L=Reston, O=Example, OU=Infrastructure' -Commit

esxi-cert-renew 1.0.0  vCenter vcsa01.example.com (8.0.3), certificate mode custom
renew certificates that expire within 90 days; COMMIT: changes are made, one host at a time
certificate folder: /srv/rotation/certs

HOST               CLUSTER  EXPIRES      DAYS  ISSUER                PLAN
esx01.example.com  cl01     2026-12-07     20  VMCA                  WRITE CSR: still on a VMCA certificate
esx02.example.com  cl01     2029-05-05    900  VMCA                  WRITE CSR: still on a VMCA certificate
esx03.example.com  cl01     2026-11-27     10  VMCA                  WRITE CSR: still on a VMCA certificate
esx04.example.com  cl01     2026-12-02     15  VMCA                  SKIP: still on a VMCA certificate, but ESXi 8.0.2.0 is older than 8.0 Update 3, which cannot take a certificate through the API without a restart (README)
esx05.example.com  cl02     2026-12-12     25  Example Issuing CA 1  WRITE CSR: 25 days left
esx06.example.com  cl02     2026-11-22      5  VMCA                  SKIP: not connected (disconnected): reconnect it first
esx07.example.com  cl02     2026-12-27     40  VMCA                  WRITE CSR: still on a VMCA certificate
esx09.example.com  cl02     2027-01-06     50  VMCA                  WRITE CSR: still on a VMCA certificate
esx08.example.com           2028-10-17    700  VMCA                  WRITE CSR: still on a VMCA certificate

  esx01.example.com: generating a CSR on the host
  esx01.example.com: wrote /srv/rotation/certs/esx01.example.com.csr
  esx02.example.com: generating a CSR on the host
  esx02.example.com: wrote /srv/rotation/certs/esx02.example.com.csr
  esx03.example.com: generating a CSR on the host
  esx03.example.com: wrote /srv/rotation/certs/esx03.example.com.csr
  esx05.example.com: generating a CSR on the host
  esx05.example.com: wrote /srv/rotation/certs/esx05.example.com.csr
  esx07.example.com: generating a CSR on the host
  esx07.example.com: wrote /srv/rotation/certs/esx07.example.com.csr
  esx09.example.com: generating a CSR on the host
  esx09.example.com: wrote /srv/rotation/certs/esx09.example.com.csr
  esx08.example.com: generating a CSR on the host
  esx08.example.com: wrote /srv/rotation/certs/esx08.example.com.csr

7 CSR(s) written. Have them signed, save each certificate next to its CSR as <host>.crt, then run the same command again.

Seven requests, each generated on its own host, each for a key that never leaves that host. The host on 8.0 Update 2 is left for after its upgrade, because before Update 3 a host cannot be told to start using a new certificate without restarting its agents. -Days 90 instead of 30 is for the calendar: a CA with a change process needs the lead time. The request, as the simulated host wrote it:

openssl req -in certs/esx01.example.com.csr -noout -subject -text

Public-Key: (2048 bit)
DNS:esx01.example.com
subject=C=US, ST=Virginia, L=Reston, O=Example, OU=Infrastructure, CN=esx01.example.com

In the rehearsal a throwaway CA signed them with openssl. Against a Microsoft CA it is one line per host:

certreq -submit -config "ca01.example.com\Example Issuing CA 1" -attrib "CertificateTemplate:WebServer" certs\esx01.example.com.csr certs\esx01.example.com.crt

I had the rehearsal’s CA make two mistakes on purpose, the two I would expect from a real one. One certificate was issued for the wrong host name, and one came from a template with a 30-day life. The second run of the same command reads the folder before it touches a host:

HOST               CLUSTER  EXPIRES      DAYS  ISSUER                PLAN
esx01.example.com  cl01     2026-12-07     20  VMCA                  WOULD install: esx01.example.com.crt, issued by Example Issuing CA 1, expires 2028-11-16; first refresh CA certificates on the 4 host(s) of cl01 that do not list its CA chain, and install only if vCenter trusts the chain
esx02.example.com  cl01     2029-05-05    900  VMCA                  SKIP: esx02.example.com.crt: its Subject Alternative Name does not include esx02.example.com
esx03.example.com  cl01     2026-11-27     10  VMCA                  WOULD install: esx03.example.com.crt, issued by Example Issuing CA 1, expires 2028-11-16
esx04.example.com  cl01     2026-12-02     15  VMCA                  SKIP: still on a VMCA certificate, but ESXi 8.0.2.0 is older than 8.0 Update 3, which cannot take a certificate through the API without a restart (README)
esx05.example.com  cl02     2026-12-12     25  Example Issuing CA 1  WOULD install: esx05.example.com.crt, issued by Example Issuing CA 1, expires 2028-11-16; first refresh CA certificates on the 3 host(s) of cl02 that do not list its CA chain, and install only if vCenter trusts the chain
esx06.example.com  cl02     2026-11-22      5  VMCA                  SKIP: not connected (disconnected): reconnect it first
esx07.example.com  cl02     2026-12-27     40  VMCA                  SKIP: esx07.example.com.crt: it expires 2026-12-17, within 90 days
esx09.example.com  cl02     2027-01-06     50  VMCA                  WOULD install: esx09.example.com.crt, issued by Example Issuing CA 1, expires 2028-11-16
esx08.example.com           2028-10-17    700  VMCA                  WOULD install: esx08.example.com.crt, issued by Example Issuing CA 1, expires 2028-11-16; first refresh its CA certificates, and install only if vCenter trusts the chain

5 host(s) to change. Run again with -Commit.

Five to install and two refused, each with the reason. The script also refuses a certificate that is not for the key in the host’s request, a wildcard, a CA certificate, a SHA-1 signature, a key usage without Digital Signature and Key Encipherment, and any chain that vCenter does not trust. With -Commit:

  esx01.example.com: refreshing CA certificates on esx01.example.com, esx02.example.com, esx03.example.com, esx04.example.com
  esx01.example.com: installing esx01.example.com.crt (issued by Example Issuing CA 1, expires 2028-11-16)
  esx01.example.com: done: expires 2028-11-16, issued by Example Issuing CA 1; port 443 serves it
  esx03.example.com: installing esx03.example.com.crt (issued by Example Issuing CA 1, expires 2028-11-16)
  esx03.example.com: done: expires 2028-11-16, issued by Example Issuing CA 1; port 443 serves it
  esx05.example.com: refreshing CA certificates on esx05.example.com, esx07.example.com, esx09.example.com
  esx05.example.com: installing esx05.example.com.crt (issued by Example Issuing CA 1, expires 2028-11-16)
  esx05.example.com: done: expires 2028-11-16, issued by Example Issuing CA 1; port 443 serves it
  esx09.example.com: installing esx09.example.com.crt (issued by Example Issuing CA 1, expires 2028-11-16)
  esx09.example.com: done: expires 2028-11-16, issued by Example Issuing CA 1; port 443 serves it
  esx08.example.com: refreshing CA certificates on esx08.example.com
  esx08.example.com: installing esx08.example.com.crt (issued by Example Issuing CA 1, expires 2028-11-16)
  esx08.example.com: done: expires 2028-11-16, issued by Example Issuing CA 1; port 443 serves it

5 certificate(s) replaced and verified.

The line worth reading is the first one. Before esx01 gets its certificate, every connected host in its cluster has its CA certificates refreshed from vCenter, including the two that are not getting a certificate in this run. vSphere HA and vSAN hosts check each other’s certificates, so a cluster has to trust the new CA before its first host starts presenting it. Then the script reads the list back from the host and builds the certificate’s chain against it, and only if the root and the issuing CA are both there does it install the certificate and tell the host’s services to pick it up.

To check the script against VMware’s own client, I pointed PowerCLI’s New-VIMachineCertificateSigningRequest and Set-VIMachineCertificate at the simulator too and logged what arrived:

esx02.example.com: CSR, useIpAddressAsCommonName=false
esx01.example.com: CSR by DN "CN = esx01.example.com, C = US, L = Reston, ST = Virginia, O = Example, OU = Infrastructure"
esx01.example.com: certificate installed (esx01.example.com)
esx01.example.com: services notified (0 named)

The last three lines are, word for word, what the script’s own run left in the log for esx01: the same subject format, the same install, the same notice to the host’s services.

The plan after the round:

HOST               CLUSTER  EXPIRES      DAYS  ISSUER                PLAN
esx01.example.com  cl01     2028-11-16    729  Example Issuing CA 1  installed from esx01.example.com.crt, 729 days left
esx02.example.com  cl01     2029-05-05    900  VMCA                  SKIP: esx02.example.com.crt: its Subject Alternative Name does not include esx02.example.com
esx03.example.com  cl01     2028-11-16    729  Example Issuing CA 1  installed from esx03.example.com.crt, 729 days left
esx04.example.com  cl01     2026-12-02     15  VMCA                  SKIP: still on a VMCA certificate, but ESXi 8.0.2.0 is older than 8.0 Update 3, which cannot take a certificate through the API without a restart (README)
esx05.example.com  cl02     2028-11-16    729  Example Issuing CA 1  installed from esx05.example.com.crt, 729 days left
esx06.example.com  cl02     2026-11-22      5  VMCA                  SKIP: not connected (disconnected): reconnect it first
esx07.example.com  cl02     2026-12-27     40  VMCA                  SKIP: esx07.example.com.crt: it expires 2026-12-17, within 90 days
esx09.example.com  cl02     2028-11-16    729  Example Issuing CA 1  installed from esx09.example.com.crt, 729 days left
esx08.example.com           2028-11-16    729  Example Issuing CA 1  installed from esx08.example.com.crt, 729 days left

Nothing to do.

Five hosts on the company CA, and four lines that say exactly what is still owed: a certificate to reissue for esx02 and esx07, an upgrade for esx04, a reconnect for esx06. Run it again next week and it picks up from there.

What the Rehearsal Caught

The reason to rehearse is the list of things that were wrong. The first version of the script passed its own unit checks. This is what the simulator, and a second read of the code against it, found afterwards. Each one is now a check:

  • A renewal that made things worse. Against the vCenter with the short-lived root, the first version renewed, then noticed the new certificate was no better and reported a failure. By then the host had already been changed for nothing. The check moved in front of the renewal.
  • A cluster that was only partly told. Scoped to one host with -VMHost, the script refreshed CA certificates on that host alone and left its three cluster peers without the new CA. Peers now come from the whole inventory, whatever the scope.
  • Requests written to the wrong folder. A full path given to -CertFolder was treated as a relative one, so the CSRs landed in a folder nobody would look in.
  • A host that goes by another name. For a host that calls itself something other than what vCenter calls it, the request was written and would have been signed, and ESXi then refuses the certificate with Cannot change the host configuration (KB 397317). The script now compares the two names in the plan and writes no request when they differ.
  • A file from a real CA. A Microsoft CA’s “certificate chain” download is a PKCS#7 bundle inside lines that say CERTIFICATE. The first version called it unreadable. It reads it now, along with .p7b, DER, and a PEM file with the chain in it.
  • A VMCA under another name. The script told VMCA’s certificates from a company CA’s by VMCA’s default name. On a vCenter whose VMCA root was regenerated under another name, or made a subordinate of the company CA, it would have refused every host and offered no way forward. The plan now names the issuer it did not recognise, and -VmcaIssuer says that issuer is VMCA.

What It Has Not Done

It has not run against a production vCenter. A simulator built from documentation proves the script’s logic, its order of operations and its handling of every failure somebody wrote down. It does not prove vCenter, and a model is only as good as its sources. Three things in particular are untested outside the model: how long a real vCenter takes to show an imported certificate (KB 410036 says it sometimes needs a disconnect and reconnect, and the script says so when it times out), a vSAN cluster, for which Broadcom still documents a separate procedure (KB 317244), and Windows PowerShell 5.1, which was checked by analyzer profile and not run.

So the first live run is the plan, which changes nothing, and the second is one host with -VMHost in a window. When it has run at a customer, this story gets a second part.

Lessons

  • A finished task is not a changed certificate. Read the certificate back from vCenter, then ask the host’s port 443 what it is actually serving. Both, every time.
  • Refuse before, not after. Every check that can run before a change should. The one that ran after a renewal was the worst bug in the first version.
  • Trust first, and for the whole cluster. The CA goes into vCenter before the first request is written, and onto every host of a cluster before the first host there presents a certificate from it.
  • One request per host per round. The key lives on the host and a new request replaces it. A folder holds one round, and the next round gets a new folder.
  • Rehearse the failures. The plain case, one due host and a VMCA that answers, was right the first time. Nearly everything in the list above lives off that path, where nothing runs until something is built to fail.

References


Repository: github.com/noahfarshad/esxi-cert-renew (release 1.0.0: the script, and the simulator and its 68 checks under bench/)

Related Stories:

Scroll to Top