A pedant that hangs out in the dark corner-cases of the web.

Wednesday, September 26, 2012

PowerShell: Get the SSL expiration date from a server

C:\> $req = [Net.HttpWebRequest]::Create('https://www.example.net/')
C:\> $req.GetResponse() |Out-Null
C:\> $req.ServicePoint.Certificate.GetExpirationDateString()
2/20/2014 04:00:00
C:\> 'www.example.org','www.example.com','www.example.net' |
>> % {$req = [Net.HttpWebRequest]::Create("https://$_/")
>> try{$req.GetResponse() |Out-Null}catch{}
>> "$($req.Address.Host): $($req.ServicePoint.Certificate.GetExpirationDateString())"}
>> 
www.example.org: 2/20/2014 04:00:00
www.example.com: 1/15/2014 04:00:00
www.example.net: 2/15/2014 16:44:57