WMI and CIM dates

A question on the forum asked about extracting the year from the ReleaseDate property returned by Win32_BIOS


They were trying to do this

Get-CimInstance Win32_BIOS | Select-Object @{n=”ReleaseDate”;e={$_.ConvertToDateTime($_.ReleaseDate).year()}}


There are 2 problems with this approach – firstly the objects that Get-CimInstance produces don’t have the ConvertToDateTime method (its added by PowerShell to the objects produces by Get-WmiObject) and secondly on a DateTime object Year is a property not a method.


If you use the WMI cmdlet you see this

£> Get-WmiObject -Class Win32_Bios | select Releasedate



The date is in WMI format and needs to be converted.

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

12/05/2014 01:00:00


If you want just the year

£> Get-WmiObject Win32_BIOS | Select-Object @{n=”ReleaseDate”;e={($_.ConvertToDateTime($_.ReleaseDate)).Year}}



This conversion is already done for you with the CIM cmdlets

£> Get-CimInstance -CimSession $c -ClassName Win32_Bios | select ReleaseDate

12/05/2014 01:00:00


Again if you just want the year

£> ((Get-CimInstance -CimSession $c -ClassName Win32_Bios).ReleaseDate).Year

This entry was posted in CIM, PowerShell and WMI. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s