Date oddity

This topic contains 3 replies, has 4 voices, and was last updated by  David Zemdegs 4 years, 10 months ago.

  • Author
  • #4590



    Hope this isent a problem connected to he wine and time 😉 and I havent been working with PS for more then a few weeks....

    I run the Command and get the output:

    PS C:\temp> Get-ADComputer -Identity "gandalf" -Properties lastlogon | Select-Object -ExpandProperty lastlogon | Get-Date

    den 20 mars 0413 13:29:56


    What im wondering is what is 0413 ?


    When running

    PS C:\temp> invoke-command -ComputerName gandalf -ScriptBlock {get-date}

    den 11 maj 2013 22:43:15

    It looks correct......


    Hope its just not me beeing dumb :-S

  • #4621

    Don Jones

    LastLogon probably isn't formatted as a proper DateTime, so when you pipe it to Get-Date, Get-Date doesn't quite know what to do with it. That'd be my guess.

  • #4649

    Jeffrey Smith

    Yeah, the lastLogon property isn't a .NET DateTime value, but instead a 'FileTime' type. When Get-Date tries to parse the string into one, it's failing a little bit on the year and hours. It looks like a byte-order/Endian sort of thing.


    But thankfully, the .NET framework is prepared for this, and the DateTime class has a static FromFileTime method to parse the string correctly. Try this instead:

    [DateTime]::FromFileTime((Get-ADComputer -Identity “gandalf” -Properties lastlogon | Select-Object -ExpandProperty lastlogon))


  • #4695

    David Zemdegs

    Microsoft often use the year 1600 as a base. So you might have to add 1600 as it appears that 0413 + 1600 = 2013!

You must be logged in to reply to this topic.