none
LastLogonTimeStamp Convert date RRS feed

  • Question

  • Hi everyone,

    I have a PS script with line:

    $stamp = (Get-ADComputer $Computername -Properties LastLogonTimeStamp).LastLogonTimeStamp

    How do I convert $stamp to a human readable format?  Thanks.

    Thursday, June 26, 2014 11:10 AM

Answers

  • Try this:

    [datetime]::fromfiletime($stamp)

    That will get you a [datetime] object, and you can format that however you want.


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "


    Thursday, June 26, 2014 11:20 AM
    Moderator
  • Hi Phat,

    you can go two ways:

    $stamp = (Get-ADComputer $Computername -Properties LastLogonDate).LastLogonDate

    or

    $stamp = [System.DateTime]::FromFileTime((Get-ADComputer $Computername -Properties LastLogonTimeStamp).LastLogonTimeStamp)

    Both ought to give you exactly the same datetime, I'd say the first way is significantly simpler and easier to read.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Marked as answer by phathuynh27 Thursday, June 26, 2014 11:52 AM
    Thursday, June 26, 2014 11:22 AM
  • Like this:

    #
    $stamp=[datetime]::FromFileTime(Get-ADComputer $Computername -Properties LastLogonTimeStamp).LastLogonTimeStamp)
    

    This does not tell you when someone logged on.  It has nothing to do with logons.


    ¯\_(ツ)_/¯


    • Edited by jrv Thursday, June 26, 2014 11:22 AM
    • Marked as answer by phathuynh27 Thursday, June 26, 2014 11:52 AM
    Thursday, June 26, 2014 11:22 AM

All replies

  • Try this:

    [datetime]::fromfiletime($stamp)

    That will get you a [datetime] object, and you can format that however you want.


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "


    Thursday, June 26, 2014 11:20 AM
    Moderator
  • Hi Phat,

    you can go two ways:

    $stamp = (Get-ADComputer $Computername -Properties LastLogonDate).LastLogonDate

    or

    $stamp = [System.DateTime]::FromFileTime((Get-ADComputer $Computername -Properties LastLogonTimeStamp).LastLogonTimeStamp)

    Both ought to give you exactly the same datetime, I'd say the first way is significantly simpler and easier to read.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Marked as answer by phathuynh27 Thursday, June 26, 2014 11:52 AM
    Thursday, June 26, 2014 11:22 AM
  • Like this:

    #
    $stamp=[datetime]::FromFileTime(Get-ADComputer $Computername -Properties LastLogonTimeStamp).LastLogonTimeStamp)
    

    This does not tell you when someone logged on.  It has nothing to do with logons.


    ¯\_(ツ)_/¯


    • Edited by jrv Thursday, June 26, 2014 11:22 AM
    • Marked as answer by phathuynh27 Thursday, June 26, 2014 11:52 AM
    Thursday, June 26, 2014 11:22 AM
  • Thanks everyone for your fast response.
    Thursday, June 26, 2014 11:53 AM