Skip to content
Menu

Certificate About to Expire on This PC

Reads the certificates in the LocalMachine stores you name and alerts on any that expired or expire within Days days, skipping superseded certificates and, by default, self-signed ones.

Certificate about to expire on this PC is free for members.

Enter your email to create your free account and get the file.

We'll email you the script and the weekly MSP Outpost email. Unsubscribe anytime. Privacy policy.

Already a member? Sign in.

Be the first to review Certificate about to expire on this PC. Tell other MSPs how it worked for you.

Write a Review

LanguagePowerShell
Runs onWindows 10, Windows 11, Windows Server 2016+; runs as SYSTEM
NeedsPowerShell 5.1; administrator rights
Read-onlyReads, changes nothing

What It Does

The script is read-only. It reads the certificates in the LocalMachine certificate stores named in Stores, which default to Personal, shown as My, and alerts when any has already expired or expires within Days days.

Self-signed certificates, where the subject equals the issuer, are left out, because Windows creates many of them itself, for Remote Desktop, WinRM and device certificates, and renews them on its own. Set IncludeSelfSigned to true to check them too. Root and intermediate authority stores are not checked unless you name them in Stores. A certificate is not flagged when a newer one with the same subject and issuer is in the same store, as an IIS or win-acme renewal leaves behind, and Windows' own short-lived Entra device certificates are ignored.

Each flagged certificate is one row: store, subject, issuer, expiry date in UTC, days left, where negative means expired, thumbprint, and whether the PC holds its private key. Only LocalMachine stores are checked. For a certificate bound by IIS, RDP or LDAPS, list its machine store. Certificates in CurrentUser stores are outside this check. Needs administrator rights.

Before You Run It

  • Name the stores your services use in Stores, such as My, WebHosting or Remote Desktop.
  • Set Days long enough to renew in time. The default is 30.
  • Use IncludeSelfSigned only if you care about those certificates. Windows renews many by itself.
  • Schedule it daily in your RMM and alert on exit 1.

Type and Risk

  • Type: Monitor. It checks one condition. It exits 1 when it finds the problem, so your RMM can alert on it, 0 when all is well, and 2 when it could not run.
  • Risk: Low. It reads and changes nothing.
  • Restart: It never restarts the machine.
  • Typical run: Under 10 seconds.
  • Example answer: "2 certificates expired or expiring within 30 days (1 expired); first: CN=mail.contoso.com in 6 day(s)"
  • Tested before listing on Windows 11 with Windows PowerShell 5.1, run as SYSTEM, against its own test cases.

Inputs

Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.

  • Days: Alert on certificates that expire within this many days (and on those already expired). Whole number, 0 to 3650. Default 30.
  • Stores: LocalMachine certificate stores to check, separated by commas or semicolons. Default My. Examples: My, WebHosting, "Remote Desktop".
  • IncludeSelfSigned: Also check self-signed certificates. true or false. Default false.

Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.

License

Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.

The Script

test-certificate-expiry.ps1 · 839 lines · 42.6 KB

Free for Members

Create a free account or sign in to read, copy and download this script.

Welcome Back

Sign in to your MSP Outpost account.