Date oddity


Hope this isent a problem connected to he wine and time :wink: 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

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.

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


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