We created an external node tied to an external web server that has about 6 of our external sites located in there via IIS. Through the windows powershell Monitor, we were able to tie a powershell script to a specific URL in the script arguments and this came back with the expiration date as expected. However, as of a few days ago, we're getting an error and the script is now saying each of those sites will expire in -739110 days. One other thing to note, I've used this same script for other external websites of ours and it outputs without a problem. I don't know what's changed. I'm going to paste the powershell here. Something must have changed with the web server but I don't really know what could be the cause. Does anyone have a suggestion?
param (
[string]$url
)
write-host "Checking $url"
# Disabling the cert validation check. This is what makes this whole thing work with invalid certs...
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$req = [Net.HttpWebRequest]::Create($url)
try {
$req.GetResponse() | Out-Null
} catch {
Write-Host "Exception while checking URL $url`: $_" -ForegroundColor Red
}
$certExpiresOnString = $req.ServicePoint.Certificate.GetExpirationDateString()
[datetime]$expiration = [System.DateTime]::Parse($req.ServicePoint.Certificate.GetExpirationDateString())
[int]$certExpiresIn = ($expiration - $(get-date)).Days
Write-Host "Cert for site $url expires in $certExpiresIn days [on $expiration]"
Write-Host "Message : Cert for site $url expires in $certExpiresIn days [on $expiration]"
Write-Host "Statistic: $certExpiresIn"
Exit 0
rv req
rv expiration
rv certExpiresIn