none
Want the the script output to be on event logs RRS feed

  • Question

  • Hi guys,

    we got a powershelll script to monitor the certificate expiry dates which is below; it working fine by showing the outputs on the power shell window itself, but we want this output to be written on event logs with below values

    Log name : Application

    Source : script

    event ID : 666

    Script is below;

    $minimumCertAgeDays = 60
     $timeoutMilliseconds = 10000
     $urls = @(
     "https://www.abcd.com",
     "https://google.com",
     "https://www.mywebsite.com"
     
     )
    #disabling the cert validation check. This is what makes this whole thing work with invalid certs...
     [Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
    foreach ($url in $urls)
     {
     Write-Host Checking $url -f Green
     $req = [Net.HttpWebRequest]::Create($url)
     $req.Timeout = $timeoutMilliseconds
    try {$req.GetResponse() |Out-Null} catch {Write-Host Exception while checking URL $url`: $_ -f Red}
    [datetime]$expiration = $req.ServicePoint.Certificate.GetExpirationDateString()
     [int]$certExpiresIn = ($expiration - $(get-date)).Days
    $certName = $req.ServicePoint.Certificate.GetName()
     $certPublicKeyString = $req.ServicePoint.Certificate.GetPublicKeyString()
     $certSerialNumber = $req.ServicePoint.Certificate.GetSerialNumberString()
     $certThumbprint = $req.ServicePoint.Certificate.GetCertHashString()
     $certEffectiveDate = $req.ServicePoint.Certificate.GetEffectiveDateString()
     $certIssuer = $req.ServicePoint.Certificate.GetIssuerName()
    if ($certExpiresIn -gt $minimumCertAgeDays)
     {Write-Host Cert for site $url expires in $certExpiresIn days [on $expiration] -f Green}
     else
     {Write-Host Cert for site $url expires in $certExpiresIn days [on $expiration] Threshold is $minimumCertAgeDays days. Check details:`n`nCert name: $certName`nCert public key: $certPublicKeyString`nCert serial number: $certSerialNumber`nCert thumbprint: $certThumbprint`nCert effective date: $certEffectiveDate`nCert issuer: $certIssuer -f Red}
    rv req
     rv expiration
     rv certExpiresIn

     
     }

    Can some one please modify this script so that the outputs will be written in event logs.

    • Moved by Bill_Stewart Wednesday, December 12, 2018 9:42 PM This is not "scripts on demand"
    Tuesday, September 11, 2018 10:11 AM