locked
Seems bug is present in Get-Date cmdlet for some date-strings prepared by Get-WinEvent RRS feed

  • General discussion

  • > Get-Date "2018-05-09T18:09:26.990894900Z"
    Wednesday, May 9, 2018 22:09:26
    > Get-Date "‎2018‎-‎08‎-‎14T04:01:13.496081100Z"
    Get-Date : Cannot bind parameter 'Date'. Cannot convert value "‎2018‎-‎08‎-‎14T04:01:13.496081100Z" to type "System.DateTime". Error: "String was not recognized
    as a valid DateTime."
    At line:1 char:10
    + get-date "‎2018‎-‎08‎-‎14T04:01:13.496081100Z"
    +          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Get-Date], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetDateCommand

    Bug happens very seldom but happens :)

    • Changed type Bill_Stewart Wednesday, December 12, 2018 5:05 PM
    Tuesday, August 14, 2018 2:36 PM

All replies

  • Interesting. What's your question?

    -- Bill Stewart [Bill_Stewart]

    Tuesday, August 14, 2018 4:02 PM
  • # this way
    [datetime]'2018-05-09T18:09:26.990894900Z'

    # or this way
    $dmtf = [System.Management.ManagementDateTimeConverter]::ToDmtfDateTime('2018-05-09T18:09:26.990894900Z') [System.Management.ManagementDateTimeConverter]::ToDateTime($dmtf)



    \_(ツ)_/


    • Edited by jrv Tuesday, August 14, 2018 4:19 PM
    Tuesday, August 14, 2018 4:18 PM
  • It is likely you are extracting the string incorrectly and it is not a string but an array with one null field.


    \_(ツ)_/

    Tuesday, August 14, 2018 4:20 PM
  • jrv is likely correct (the behavior you are seeing is probably caused by how you are passing a string to Get-Date, not in how the Get-Date cmdlet works).

    -- Bill Stewart [Bill_Stewart]

    Tuesday, August 14, 2018 5:18 PM