Bios Date -> year only

Welcome Forums General PowerShell Q&A Bios Date -> year only

This topic contains 4 replies, has 4 voices, and was last updated by

4 years, 6 months ago.

  • Author
  • #18985

    Points: 0
    Rank: Member

    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()}}

  • #18986

    Points: 0
    Rank: Member

    This will work – assuming the release date is populated

    £> Get-CimInstance -ClassName Win32_Bios | select 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}}


    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

  • #18987

    Points: 0
    Rank: Member

    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
  • #18989

    Points: 1
    Rank: Member

    How about this?

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

  • #19011

    Points: 0
    Rank: Member

    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}}

The topic ‘Bios Date -> year only’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort