Bios Date -> year only

I’m trying to get the year from the bios releasedate, The following command gives me an empty result:

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

This will work - assuming the release date is populated

£> Get-CimInstance -ClassName Win32_Bios | select ReleaseDate

ReleaseDate

12/05/2014 01:00:00

With the WMI cmdlets you had to convert the date - you also have a bug in your code as Year is a property not a method. So use this

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

OR

the CIM cmdlet returns the date in a string so you need to extract the year

Get-CimInstance -ClassName Win32_Bios | select @{N=‘ReleaseYear’; E={(($_.ReleaseDate -split “/”)[2] -split " ")[0]}}

You can’t easily assume date format - .NET needs dates in MM/DD/YYYY to convert string to date

I’m pretty sure the Get-CimInstance cmdlet will return the property as a DateTime object, not a string. Does this work for you?

(Get-CimInstance Win32_BIOS).ReleaseDate.Year

How about this?

Get-CimInstance Win32_BIOS | Select-Object @{n=“ReleaseDate”;e={$_.ReleaseDate | select -expand Year}}

Thank you all for the replies. It all worked… I ended up using the following:

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