[SOLVED] Get-ADuser -property pwdLastSet giving wrong year?

This topic contains 4 replies, has 2 voices, and was last updated by Profile photo of sponsen sponsen 1 year, 9 months ago.

  • Author
    Posts
  • #22905
    Profile photo of sponsen
    sponsen
    Participant

    Hi!

    Doing som scriptbuilding and came across this strange thing, and want so hear if anybody else gets this.
    When running [b]Get-ADuser "username" -property pwdLastSet[/b] you get the property pwdLastSet. Take this number and run [b]Get-Date (number from pwdLastSet)[/b].

    The issue here is that i get something like this back: 28.feb.0415. In my mind that is incorrect. It should have ended with 2015, not 0415. Whats going on? Anyone else getting this?

  • #22907
    Profile photo of Sean Quinlan
    Sean Quinlan
    Participant

    You can use the PasswordLastSet property to get a correctly formatted date.

    Or you can use this to convert that specific integer: [datetime]::fromfiletimeutc(number from pwdLastSet)

  • #22908
    Profile photo of sponsen
    sponsen
    Participant

    thanks! That is great! But, is this "normal", that pwdLastSet is giving a string that is acting like that with get-date? Do you see the same behavior on your environment if you have one available?

  • #22909
    Profile photo of Sean Quinlan
    Sean Quinlan
    Participant

    Yes, I get the same output you get when I feed that long number to Get-Date.

    The number stored in AD is the miliseconds since 1/1/1600. However it looks like if you give Get-Date a long integer, it assumes that this is miliseconds since 1/1/0000. That's why the date is exactly 1600 years off.

  • #22910
    Profile photo of sponsen
    sponsen
    Participant

    aha, makes sense. thanks for the clarification – have a nice day! 🙂

You must be logged in to reply to this topic.