Skip to content
Menu

Public SSL Certificate About to Expire (TLS Check of Your Sites)

Connects to each host and port, reads the TLS certificate and alerts when it expires within WarningDays, has expired, or fails the name or chain check.

Public SSL certificate about to expire (TLS check of your sites) 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 Public SSL certificate about to expire (TLS check of your sites). Tell other MSPs how it worked for you.

Write a Review

LanguagePowerShell
Runs onWindows 10, Windows 11, Windows Server 2016+; runs as SYSTEM or a user
NeedsPowerShell 5.1, outbound TCP to each host and port
Read-onlyReads, changes nothing

What It Does

The script is read-only. For each host it opens a TCP connection to host:port, 443 unless you give a port, completes a TLS 1.2 handshake with the host name as SNI, reads the certificate the server presents, and closes the connection without sending application data. It writes one row per host with the state, subject, issuer, expiry date and days left.

It alerts, with exit 1, when a certificate expires within WarningDays days, has already expired, does not match the host name, or does not chain to a root this computer trusts. The handshake uses a callback that records what Windows found wrong so it can be reported; name mismatches and relevant chain errors become alerts. The TLS handshake does not request a revocation check.

A host is marked Unreachable when the connection or TLS 1.2 handshake does not yield a certificate. If nothing else alerts, that is an error, so a monitor that could not look is never reported as healthy. IPv6 literals are not supported, and neither are hosts that require a client certificate or a STARTTLS protocol such as mail ports.

The check sees what this computer sees. A site that serves a different certificate to different networks is judged from here, so run it from where you want the answer to be true.

Before You Run It

  • List each public name that carries a certificate, and add the port for anything not on 443.
  • Set WarningDays to give you time to renew. The default is 21 days.
  • Allow outbound TCP from the PC to each host and port.
  • Do not point it at mail ports that use STARTTLS, or at a host that requires a client certificate. They are not supported.
  • Schedule it 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: A second or two per host.
  • Example answer: "www.contoso.com expires in 9 day(s); warning at 21 days"
  • 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.

  • Hosts: The sites to check, separated by commas, semicolons or new lines. Each is a host name or host:port, for example "www.contoso.com, mail.contoso.com:8443". Required. At most 100.
  • WarningDays: Alert when a certificate expires within this many days. Whole number, 1 to 365. Default 21.
  • TimeoutSeconds: Seconds to wait for the connection and for the handshake of each host. Whole number, 2 to 120. Default 10.

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-public-certificate-expiry.ps1 · 883 lines · 45.2 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.