locked
Azure Automation Runbook returning incorrect date (PowerShell) RRS feed

  • Question

  • Hello, I am working on a PowerShell runbook that checks the expiration date of some website SSL certificates.  The script runs fine, but the returned dates are incorrect and are the same.  I tried to convert from UTC after reading that Azure Automation was UTC time, but I am not sure that I am doing that correctly.  The code runs fine on my laptop, we have no restrictions in place that would prevent the code from reaching the sites (we own them).  

    These are the dates returned for the certs in the runbook

    These are the correct dates when running from my laptop using the exact same code.

    Here is the code I am using which actually gave the correct dates the very first time I ran it in test.  The runbook is saved, but not published.  Not sure if that has something to do with it or not

    $sites = Import-Csv "$env:temp\testsites.csv" $colResults = @() ForEach($site in $sites){ $baseName = $site.BaseName.tostring(); $url = [string]::Concat("https://",$baseName,".com") $request = [System.Net.HttpWebRequest]::Create($url) $request.UseDefaultCredentials = $true $request.UserAgent ="Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)" try { $request.GetResponse().Dispose() } catch [System.Net.WebException] { if ($_.Exception.Status -eq [System.Net.WebExceptionStatus]::TrustFailure) { } else { throw } } $servicePoint = $request.ServicePoint $cert = $servicePoint.Certificate $expirationDate = [datetime] $(Get-Date -Date $cert.GetExpirationDateString()) $expirationDate

    <# Commented out code, does not execute $tempDate = (Get-Date -Date $(Get-CertificateExpirationDate -uri $url)).ToUniversalTime() $tzEST = [System.TimeZoneInfo]::FindSystemTimeZoneById("Eastern Standard Time") $expirationDate = [System.TimeZoneInfo]::ConvertTimeFromUtc($tempDate, $tzEST) $obj = New-Object psobject -prop @{ BaseName = $baseName Url = $url ExpirationDate = $expirationDate } $colResults+=$obj #> }

    Thanks for the assistance


    &amp;quot;I live and die by the command line&amp;quot; -JL 2010 &copy; &#169;


    • Edited by JL-4 Thursday, April 30, 2020 3:40 PM clarify some code
    Thursday, April 30, 2020 3:38 PM

Answers

  • Please disregard this.  The runbook is operating as expected as well as the powershell code.  It seems that we are actually getting the Akamai edge service certificate instead of the actual SSL certificate

    &amp;quot;I live and die by the command line&amp;quot; -JL 2010 &copy; &#169;

    Thursday, April 30, 2020 6:33 PM

All replies

  • Please disregard this.  The runbook is operating as expected as well as the powershell code.  It seems that we are actually getting the Akamai edge service certificate instead of the actual SSL certificate

    &amp;quot;I live and die by the command line&amp;quot; -JL 2010 &copy; &#169;

    Thursday, April 30, 2020 6:33 PM
  • Hi JL-4,

    Glad to know that you have self resolved the issue. Thanks for letting us know the reason.
    Friday, May 1, 2020 5:16 AM