I recently setup LetsEncrypt on this blog. With all the insecure connection url bar indicators quickly becoming default on the modern browsers, this great open source project really comes through and makes securing your site with a SSL/TLS certificate easy. And of course, in the spirit of open source, the certificates are free!
As part of using LetsEncrypt, you need to automate your certificate renewals. So once I got everything setup and a cron job configured to handle the renewals, I wanted to log the date of my current certificate from a web call on my home computer.
Here is the PowerShell I used to get the certificate date information which then can be logged
1 2 3 4 |
$webcall = Invoke-WebRequest https://packetlost.com/blog $servicePoint = [System.Net.ServicePointManager]::FindServicePoint("https://packetlost.com/blog") $servicePoint.Certificate.GetCertHashString() $servicePoint.Certificate.GetExpirationDateString() |
I was looking for a script that did this. Thanks!!
1. what does $webcall do in that code?
2. if i run that code, i get “you cannot call a value on a null-valued expression” twice, because ‘certificate’ is blank in $servicepoint.
Hey Curtiss. I would dive into the microsoft class documentation for a more thorough explanation but from what I remember the web call to the same url was a prerequisite for the service point code to work. This post is quite dated so this would apply to powershell 4/5.