Hello All
I came across the following today, so thought I would make a brief post. I created a script to check expiry dates of SSL certificates (nice an easy with PowerShell thanks the the cert: psdrive)
Now I my certifcate is in the $cert variable (I am in the UK time zone and my PowerShell culture is therefore set to en-GB)
so if I do this
$Cert.NotAfter
it returns the following
06 March 2013 00:00:00
Which is correct the cert does indeed expire on the 6th March.
However if I do this
"Expires on: $($Cert.NotAfter) `r`n"
it returns
Expires on: 03/06/2013 00:00:00
Not the above US format i.e. 3rd June now not the 6th March.
Now I assume this has to do with the fact the first example returns a property (NotAfter) from object type X509Certificate2
The second time the overall object is a String. So I am thinking the result of the expression $($Cert.NotAfter) is being miss-interpreted by PowerShell.
Therefore, I fixed as follows
"Expires on: $(($Cert.NotAfter).ToString()) `r`n"
which returns
Expires on: 06/03/2013 00:00:00
i.e. correct, the reason this mattered was I write custom SCOM (System Center Operations Manager) PowerShell based monitors to alert people to issues, so the alert was sent out correctly i.e. within 30 days of cert expirty (together with all the certificate information etc) but worded it did not expire to the 3rd June which was wrong.
Can one of the experts on the forum unlighten me (any one else with an interest) to this behaviour
Thanks again
Ernie