Convert Active Directory pwdLastSet attribute to readable time

This Active Directory attribute pwdLastSet uses a timestamp that is stored as a large integer that represents the number of 100 nanosecond intervals since 1 January 1601. When we’re familiar with working with Unix epoch time, it is not really handy. Epoch is an integer that represents the time since 1 January 1970.

How to convert pwdLastSet to Unix epoch :

  • Divide by 10’000’000 pwdLastSet to convert in seconds
  • Substract 11’644’473’600 (this is the difference in second between the 1 January 1601 and 1970)

Example ($AD_PWDLASTSET is your pwdLastSet content) :

/bin/echo $((($AD_PWDLASTSET/10000000)-11644473600))

Script to convert Unix epoch to readable time (BSD) :

AD_PWDLASTSET_EPOCH=`/bin/echo $((($AD_PWDLASTSET/10000000)-11644473600))`
AD_PWDLASTSET_HR=`/bin/date -r $AD_PWDLASTSET_EPOCH "+%d.%m.%Y"`

Script to convert Unix epoch to readable time (Standard Unix) :

AD_PWDLASTSET_EPOCH=`/bin/echo $((($AD_PWDLASTSET/10000000)-11644473600))`
AD_PWDLASTSET_HR=`/bin/date -d "1970-01-01 $AD_PWDLASTSET_EPOCH sec GMT"`

Leave a Reply

Your email address will not be published. Required fields are marked *