If you run an internal Windows CA, here’s a question worth answering before Monday: which certificates on it expire in the next 30 days? Not the public stuff on your website. The internal ones. The web server cert on the HR app, the RADIUS cert behind your Wi-Fi, the one somebody issued to a printer in 2023 and never thought about again.
Most of us can’t answer that off the top of our heads, and the Certification Authority console isn’t much help. You can sort the Issued Certificates view by expiration date, but you can’t schedule it, filter it well, or email it to anyone. The good news is that you can find expiring certificates on your Windows CA in about one line of certutil, and turn that into a scheduled report with a few more lines of PowerShell.
Let’s build it, and then talk honestly about where it stops being enough.
Why the CA database is the right place to start
Every certificate your AD CS issuing CA hands out gets a row in the CA database. That row includes who requested it, which template it used, the common name, and the expiration date (NotAfter). So the CA already knows every certificate it has ever issued and exactly when each one dies.
That makes it the best single source you have for internal certs. It won’t tell you everything (more on that later), but it’s the closest thing to an inventory most small IT teams already own. If internal certs aren’t on your radar at all right now, I wrote about why that’s a problem in the internal PKI blind spot.
How to find expiring certificates on a Windows CA with certutil
Certutil’s -view verb dumps the CA database, and -restrict filters it. Run this on the issuing CA from an elevated prompt:
certutil -view -restrict "Disposition=20,NotAfter>=now,NotAfter<=now+30:00" -out "RequestID,RequesterName,CommonName,CertificateTemplate,NotAfter"
Here’s what each piece does.
Disposition=20 limits the results to issued certificates. Microsoft’s PKI team documented the disposition values years ago: 20 means issued, 21 means revoked, 30 is a failed request, and 31 is a denied one. Without this filter you’ll get revoked certs and junk requests mixed in.
NotAfter>=now,NotAfter<=now+30:00 is the expiration window. Microsoft’s certutil reference documents now+dd:hh as the way to express a date relative to the current time, so now+30:00 means 30 days and 0 hours from now. Change it to now+60:00 for a 60-day window.
That relative syntax matters more than it looks. A lot of older examples online hard-code dates like NotAfter<=1/02/2016, and certutil parses those according to the server’s regional settings. Microsoft’s own docs warn that date arguments can produce unexpected results if the server isn’t set to US regional settings. Using now sidesteps the whole problem.
-out picks the columns. If you’re not sure what a column is called, run certutil -view with a -restrict but no -out against a single request and you’ll get every field for that row. Use that output as your cheat sheet.
Not sitting on the CA? Add -config to point at it remotely:
certutil -config "ca01.corp.example.com\Corp Issuing CA" -view -restrict "Disposition=20,NotAfter>=now,NotAfter<=now+30:00" -out "RequestID,CommonName,NotAfter"
If you have more than one issuing CA, you’ll need to run it once per CA. Keep that in mind, because it comes up again.
Turn it into a scheduled AD CS certificate expiration report
The default certutil output is a wall of text that’s fine to eyeball and awful to work with. Add csv to the end and it becomes something you can actually use. This script writes a dated CSV report you can email, drop on a share, or attach to a ticket:
# Expiring certificate report for a Windows issuing CA
# Run on the CA (or add -config "Host\CA Name" to the certutil call)
$Days = 30
$Columns = "RequestID,RequesterName,CommonName,CertificateTemplate,NotAfter"
# The + in front of NotAfter sorts the results soonest-first
$Restrict = "Disposition=20,+NotAfter>=now,NotAfter<=now+$($Days):00"
$ReportPath = "C:\Reports\ExpiringCerts-$(Get-Date -Format yyyy-MM-dd).csv"
$raw = certutil -view -restrict $Restrict -out $Columns csv
if ($LASTEXITCODE -ne 0) {
Write-Error "certutil failed with exit code $LASTEXITCODE"
exit 1
}
$raw | Set-Content -Path $ReportPath
$count = ($raw | ConvertFrom-Csv).Count
Write-Output "$count certificate(s) expire in the next $Days days. Report: $ReportPath"
The plus sign in front of NotAfter is a documented -restrict feature: one column in the list can carry a + or - to set the sort order. It means the cert that dies first lands at the top of the report, which is exactly where you want it.
One heads-up on the CSV. Certutil uses the localized display names for the column headers, not the short names you passed to -out, so the header row will read something like “Issued Common Name” instead of CommonName. Open the first report and check before you write anything that parses it.
Wrap it in a scheduled task that runs weekly, send the file wherever your team actually looks, and you’ve got a basic expiration report for zero dollars.
Check the servers, too
The CA knows what it issued. It doesn’t know what’s actually installed. For that you have to look at the machines themselves. On any Windows box, PowerShell’s certificate provider can filter by expiration for you:
Get-ChildItem Cert:\LocalMachine\My -ExpiringInDays 30 |
Select-Object Subject, NotAfter, Thumbprint, Issuer
-ExpiringInDays works in Windows PowerShell 5.1, and Microsoft brought it back in PowerShell 7.1 after it went missing in earlier 7.x releases. The Issuer column is the useful one here. It’s how you spot a public cert, a cert from some other CA, or a self-signed cert sitting on a server your CA has never heard of.
Run that across a list of servers with Invoke-Command and you’ve got the other half of the picture.
Gotchas that will bite you
A few things I’d want someone to tell me before I trusted this report.
Renewed certs still show up. When a cert gets renewed, the old one doesn’t vanish from the CA database. It stays in there as issued until it expires. So your report will happily list certs that were already replaced last month. You have to cross-check against what’s actually installed before you panic, or before you ignore one that matters.
Autoenrollment adds noise. Machine and user certs from autoenrollment templates usually renew themselves. If they’re flooding your report, filter by template. Just know that for version 2 and newer templates, the CertificateTemplate column holds the template’s OID rather than its friendly name, so CertificateTemplate=WebServer may not match what you expect. Pull the OID from a sample row first.
Requester names can trip the parser. Microsoft has a known issue where -restrict mishandles requester names containing sequences like \t or \n (think CONTOSO\twilson). The workaround is to uppercase the name in the restriction.
Microsoft doesn’t love this in production. The current certutil reference says outright that certutil isn’t recommended for production code and comes with no compatibility guarantees. It works, and lots of us rely on it, but that’s the official position.
Where the script approach runs out
I like this script. For a shop with one CA and a few dozen certs, it might be all you need for a while. But be honest with yourself about what it doesn’t do.
It only sees certs your CA issued. Your public TLS certs, vendor certs, appliance certs, and the SAML signing certs in Entra ID never show up. It doesn’t know which servers a certificate lives on, so when it says the cert for app01 expires in nine days, you still have to go figure out every place that cert was copied to. It runs per CA, per server, so every new CA or server is another thing to add to the script and remember. And it produces a file. Someone has to open that file, every week, forever. The week they’re on vacation is the week it matters.
That last one is the real problem. Finding certs is the easy part. Making sure the right person acts on them, every time, is where homegrown tooling quietly fails. If you want the long version of that argument, I broke it down in certificate discovery and in manual tracking vs. CertMS.
If you’d rather not maintain it yourself
This is the exact problem I built CertMS to handle. A small PowerShell agent sits on your issuing CA and reports every certificate it issues. Lightweight agents on your Windows and Linux servers report what’s actually installed. CertMS then ties the two together, so when a cert is about to expire you see every server it lives on. Add URL monitoring for public sites and the Entra ID SAML integration, and you’ve covered the stuff the CA can’t see.
From there you get scheduled reports, plus help desk tickets or webhooks that fire a set number of days before expiration, with your own replacement notes attached so whoever gets the ticket knows how that particular cert gets swapped. CertMS only monitors. It never sits in the middle of issuance, so it works alongside the CA you already run.
If that sounds like less work than babysitting a scheduled task, take a look at CertMS. Either way, run that certutil command today. It takes thirty seconds, and you might not like what it finds.
References
- certutil command reference, Microsoft Learn
- Disposition values for certutil -view -restrict (and some creative samples), Microsoft PKI Blog archive
- How to determine all certificates that will expire within 30 days, Microsoft PKI Blog archive
- PowerShell and certutil.exe, Microsoft archive blog
- Get-Item (Certificate provider -ExpiringInDays parameter), Microsoft Learn
- Certutil -view doesn’t return issued certificates correctly, Microsoft Learn