Date oddity

Welcome Forums General PowerShell Q&A Date oddity

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

5 years, 9 months ago.

  • Author
  • #4590

    Points: 0
    Rank: Member


    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

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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

    Points: 0
    Rank: Member

    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

    Points: 23
    Rank: Member

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

The topic ‘Date oddity’ is closed to new replies.

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