I'm writing something to get the installation date for a certain program, but I can't seem to convert the number that is returned into a weird date format (yyyyMMdd). I've tried casting it to [datetime], but that returns the error below.
This may be an easy fix, but it's something I haven't run across yet. Can someone please help?
Thanks in advance!
$test = Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -eq 'exampleProgram'} | select installdate
[datetime]$test.installdate
Cannot convert value "20160628" to type "System.DateTime". Error: "String was not recognized as a valid DateTime."
At line:1 char:1
+ [datetime]$test.installdate
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvalidCastParseTargetInvocationWithFormatProvider`