0

In powershell, if i do (gwmi win32_bios).releasedate | convertto-json, I get "20171221000000.000000+000", which makes sense - Dec. 21, 2017.

But if I take the equivalent element in the CimInstanceProperties list, e.g.,

$a = (Get-CimInstance cim_bioselement).CimInstanceProperties | `
where-object {$_.name -eq 'ReleaseDate'}

and then inspect $a.value, I get

Wednesday, December 20, 2017 6:00:00 PM

but doing $a | ConvertTo-Json yields

{
    "Name":  "ReleaseDate",
    "Value":  "\/Date(1513814400000)\/",
    "CimType":  13,
    "Flags":  "Property, ReadOnly, NotModified",
    "IsValueModified":  false
}

I'm guessing somehow those two dates are equivalent, but I don't have any immediate insight into what the format is for the CIM value after jsonification. I can grab a few more bios dates from different machines and start analyzing, but was curious if anyone knew what the format was "off the top of their head".

The reason I would like to understand the format is because it is what I get if I generically try to get all of the properties and jsonify, via

(Get-CimInstance cim_bioselement).CimInstanceProperties | convertto-json
aggieNick02
  • 2,557
  • 2
  • 23
  • 36
  • 1
    Are you running this against a Windows machine? `(Get-CimInstance CIM_BiosElement).ReleaseDate` gives me a normal datetime-object directly (same as you would get after converting the wmi-format) – Frode F. Mar 29 '18 at 18:09

1 Answers1

2

There is a built in method for decoding CIMDATEs:

Get-WmiObject Win32_BIOS -Property ReleaseDate | 
    Select-Object @{n='ReleaseDate';e={$_.ConvertToDateTime($_.ReleaseDate)}}

Unless you're on PowerShell v1/v2 or run into problems, however, you should use Get-CimInstance over Get-WmiObject since it will do the conversions for you and is a bit cleaner:

PS> Get-CimInstance Win32_BIOS -Property ReleaseDate | Select-Object ReleaseDate

ReleaseDate
-----------
8/5/2014 8:00:00 PM

To avoid Microsoft's stupid non-standard JSON date syntax, format the date yourself to a string in the correct ISO 8601 format:

PS> Get-CimInstance Win32_BIOS -Property ReleaseDate |
    Select-Object @{n='ReleaseDate';e={$_.ReleaseDate.ToString('yyyy-MM-ddTHH:mm:ss.fffZ')}}

ReleaseDate
-----------
2014-08-05T20:00:00.000Z

PS> Get-CimInstance Win32_BIOS -Property ReleaseDate
    | Select-Object @{n = 'ReleaseDate'; e = {$_.ReleaseDate.ToString('yyyy-MM-ddTHH:mm:ss.fffZ')}}
    | ConvertTo-Json
{
    "ReleaseDate":  "2014-08-05T20:00:00.000Z"
}
Bacon Bits
  • 30,782
  • 5
  • 59
  • 66