SSL Certificate Tracking Spreadsheet: Build It From a Scan

Every IT team I can picture has one: a spreadsheet called something like certs-FINAL-v3.xlsx, last edited by someone who has since left, listing about half the certificates the company actually uses. When an auditor or a boss asks “how many certs do we have and when do they expire?”, that file gets opened and everyone quietly hopes it’s close.

It doesn’t have to be a guess. You can build the spreadsheet from what’s actually out there, in an afternoon, with tools you already have. Below is a script that scans a list of hosts and writes a CSV you can open in Excel, plus a few ways to find the hosts you forgot about. Then I’ll be straight about where a spreadsheet stops working.

What the spreadsheet needs to contain

Keep it small or nobody will maintain it. These columns earn their place:

  • Host and port, so you know where to look.
  • Subject and issuer, so you can tell your internal CA from a public one at a glance.
  • Not after date and days left, the whole reason the file exists.
  • Status, a plain word like ok, expiring-30d or EXPIRED you can filter on.
  • Owner and renewal notes, which no scan can fill in for you. This is the column that saves you at 2 a.m., so make a human fill it in.

Scan a host list with Bash

Put one host:port per line in hosts.txt (port defaults to 443, and lines starting with # are skipped). Then run this script. It uses openssl s_client to fetch each certificate, which connects with SNI, reads the dates, and computes what’s left.

#!/usr/bin/env bash
# cert-inventory.sh - build a CSV of the TLS certs served by a list of host:port pairs
# Usage: ./cert-inventory.sh hosts.txt > cert-inventory.csv
set -u
HOSTS_FILE="${1:?usage: $0 hosts.txt}"
TIMEOUT=10

echo "host,port,subject,issuer,not_after,days_left,status"

while IFS=: read -r host port; do
  # skip blank lines and comments
  [[ -z "${host// }" || "$host" == \#* ]] && continue
  port="${port:-443}"

  pem=$(timeout "$TIMEOUT" openssl s_client -connect "${host}:${port}" -servername "$host" </dev/null 2>/dev/null \
        | openssl x509 2>/dev/null)

  if [[ -z "$pem" ]]; then
    echo "${host},${port},,,,,unreachable-or-no-tls"
    continue
  fi

  subject=$(openssl x509 -noout -subject -nameopt RFC2253 <<<"$pem" | sed 's/^subject=//; s/,/;/g')
  issuer=$(openssl x509 -noout -issuer  -nameopt RFC2253 <<<"$pem" | sed 's/^issuer=//;  s/,/;/g')
  not_after=$(openssl x509 -noout -enddate <<<"$pem" | cut -d= -f2)
  days_left=$(( ( $(date -d "$not_after" +%s) - $(date +%s) ) / 86400 ))

  if   (( days_left < 0 ));  then status="EXPIRED"
  elif (( days_left <= 30 )); then status="expiring-30d"
  else status="ok"
  fi

  echo "${host},${port},\"${subject}\",\"${issuer}\",${not_after},${days_left},${status}"
done < "$HOSTS_FILE"

Here’s real output from a test run against four local test endpoints, one of each kind:

host,port,subject,issuer,not_after,days_left,status
localhost,9443,"CN=good.test.local","CN=good.test.local",Jan 26 12:06:56 2027 GMT,89,ok
localhost,9444,"CN=soon.test.local","CN=soon.test.local",Nov  7 12:06:56 2026 GMT,9,expiring-30d
localhost,9445,"CN=exp.test.local","CN=Test Issuing CA",Jan 10 00:00:00 2026 GMT,-291,EXPIRED
localhost,9999,,,,,unreachable-or-no-tls

A few notes on the script. It swaps commas for semicolons inside names so the CSV doesn’t break. date -d is a GNU date feature, so on macOS install GNU coreutils or adjust that line. And it only sees the certificate a server presents on that port, to a client that asks with that name. A service that only answers for certain hostnames needs the right host in your list.

Redirect the output to a file, open it in Excel, sort by days_left, and you already have a better inventory than most teams: ./cert-inventory.sh hosts.txt > cert-inventory.csv.

Finding hosts you forgot about

The hard part isn’t the script, it’s the list. Three places to look:

Sweep your own subnets. Nmap’s ssl-cert script retrieves a server’s certificate and, per its documentation, shows the validity period and subject names by default. A sweep of one network on the HTTPS port looks like this:

nmap -p 443 --script ssl-cert 10.0.10.0/24

Only scan networks you’re responsible for, and tell your security team first. Port scans light up intrusion detection systems.

Check the certificate stores on your Windows servers. Anything bound to IIS, RDP, or a service lives in the local machine store. In PowerShell, Get-ChildItem Cert:\LocalMachine\My lists it, and Microsoft’s documentation says -ExpiringInDays filters to certificates expiring in or before that many days (it was reintroduced in PowerShell 7.1). This gives you a CSV for one server:

Get-ChildItem Cert:\LocalMachine\My |
  Select-Object @{n='Host';e={$env:COMPUTERNAME}}, Subject, Issuer, NotAfter,
    @{n='DaysLeft';e={[int]($_.NotAfter - (Get-Date)).TotalDays}}, Thumbprint |
  Export-Csv -NoTypeInformation -Path ".\certs-$env:COMPUTERNAME.csv"

Run it through Invoke-Command against a server list and merge the CSVs. This is the part that isn’t visible from the network, like a certificate that exists but isn’t bound to a listening port yet.

Ask the CA. Your internal CA has a record of everything it ever issued. That’s a different data source than a scan, and it catches things no scan will. I covered the difference in certificate discovery.

Where the spreadsheet breaks

The scan gives you a snapshot. The moment you save the file, it starts going stale. A cert gets renewed on Tuesday, a new vendor portal appears on Thursday, and the CSV knows about neither.

It also needs a person. Someone has to rerun the script, merge the sources, reconcile the duplicates, and read the result. The week that person is out is the week a certificate expires, and nothing in a spreadsheet will tell you that. And the owner and renewal-notes column, the most valuable one, is the first to rot, because nothing forces anyone to update it.

None of that makes the spreadsheet a bad idea. It’s a good first inventory and a good way to find out how big the problem is. If you want to weigh doing it yourself against a tool, build vs. buy covers the costs, and manual tracking vs. CertMS is the direct comparison.

Where CertMS fits

CertMS is what you get when the spreadsheet maintains itself. A small agent on your Windows issuing CA reports what the CA issues. Lightweight PowerShell and Bash agents on your Windows and Linux servers report what’s actually installed, and a URL monitor watches the endpoints you care about. CertMS ties certificates to the servers they live on, so when one is about to expire you know where to go. You can also attach your own replacement notes to a certificate, which is the owner-and-renewal-notes column from above, living where the alert is. Scheduled reports, help desk tickets, and webhooks fire ahead of expiry. It only monitors, so it works with whatever CAs you already use. If that sounds better than rerunning a script, take a look at CertMS.

References

Free 5-Day Email Course

Learn how to automate certificate tracking and avoid costly surprises - one actionable lesson each day