Verifying Website Certificates

How can I call a URL and check if its certificate is valid? I’m trying to keep track certificates for my department’s websites, half of which are hosted on Linux machines to which I have no access. The information I’m trying to gather into an eventual report is:

URL, SubjectName, IssuerName, and dates valid (NotAfter, NotBefore)

I don’t understand how to get there from Invoke-WebRequest or Invoke-RESTMethod. I’m not asking for a full script, just a jumping off point.

Thanks,

Patrick

Are these public facing websites or internal only?

If they’re public facing, I think the best route will be to use the SSL Labs API

$response = Invoke-RestMethod 'https://api.ssllabs.com/api/v3/analyzehost=<www.example.com>&all=on'

foreach ($cert in $response.certs) {

    Write-Output $cert.subject

}