cancel
Showing results for 
Search instead for 
Did you mean: 
Create Post
Level 8

SSL Certificate Monitoring of a Website Before the site is being redirect.

Hi ,

We have a SAM Monitor for looking for the SSL certificate expiring for the websites using TLS 1.2. We are using the below PS monitor but unfortunately, it gives the Certificate details of the redirected site but not of the actual website. Can someone suggest how to modify the script below to make it show the details of the Certificate of the actual Website (Not the redirected one).

 

$WebsiteDomainName = $args[0]

 

#Get the Current Date and Time

$CurrentDT = Get-Date

 

#To support SNI, TLS1.2 needs to be forced

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::SSL3, [Net.SecurityProtocolType]::TLS12

 

try{

$req = [Net.HttpWebRequest]::Create("https://$WebsiteDomainName")

$req.GetResponse()

}

Catch{

write-error "Couldn't connect to $WebsiteDomainName - $($error[0].exception.message)"

 

 

}

 

if (!($req.ServicePoint.Certificate)) {

write-error "No Certificate returned on $WebsiteDomainName"

}

 

$req.Abort()

$certinfo = $req.ServicePoint.Certificate
#$CertCN = $certinfo.Subject
$CertCN = $certinfo.Subject.Replace("CN=", "") | %{ $_.Split(',')[0]; }
$IssuerCN = $certinfo.Issuer.Replace("CN=", "") | %{ $_.Split(',')[0]; }
$ValidTo = [DateTime]$certinfo.GetExpirationDateString();

 

$returnobj = @{

HostName = $WebsiteDomainName;

Subject = $CertCN;

Thumbprint = $certinfo.GetCertHashString();

Issuer =$IssuerCN;

SerialNumber = $certinfo.GetSerialNumberString();

Issued = [DateTime]$certinfo.GetEffectiveDateString();

Expires = [DateTime]$certinfo.GetExpirationDateString();

}

 

 

#Get the Expiration Time Left

$TimeLeft = New-TimeSpan –Start $CurrentDT –End ($returnobj.Expires)

Write-Host "Message: Website: $WebsiteDomainName using SSL Cert $CertCN CertExpiration: $ValidTo issued by $IssuerCN "
Write-Host "Statistic: $($TimeLeft.Days)"

#Write-Host "Message :Website: $WebsiteDomainName using SSL Cert $returnobj.Subject CertExpiration: $returnobj.Expires issued by #$returnobj.Issuer
#Write-Host "Statistic : " $TimeLeft.Days

#Write-Host 'Message.CommonName:' $returnobj.Subject

#Write-Host 'Statistic.CommonName:' 0

#Write-Host 'Message.Thumbprint:' $returnobj.Thumbprint

#Write-Host 'Statistic.Thumbprint:' 0

#Write-Host 'Message.CreationDate:' $returnobj.Issued

#Write-Host 'Statistic.CreationDate:' 0

#Write-Host 'Message.ExpirationDate:' $returnobj.Expires

#Write-Host 'Statistic.ExpirationDate:' $TimeLeft.Days

0 Kudos
0 Replies