#!perl # it's run on windows that's why not a full path # Code Snippet to show how to get the date of the last login time # of an AD user on windows 2003 stored in the lastLogonTimestamp attribute. # # For more inforamtion about the value and windows use of Epoch, # basically put, the number of 100-nanosecond intervals that passed between January 1, 1601 and the time the user last logged on # # Reference to the maths: http://www.microsoft.com/technet/scriptcenter/topics/win2003/lastlogon.mspx # The document also covers the issue replication of this attribute, be warned, the attribute # lastLogonTimestamp is replicated only once every 14 days. # # How to get the attribute out of AD is up to you. I was using Net::LDAP at the time. # # Hopefully this will be found and help out anyone else stuck with this problem. # use strict; # we need to handle the large int. It's a 64bit int use Math::BigInt; # Use Date::Calc to work out the days and date since 1/1/1600 use Date::Calc qw/Add_Delta_Days/; my $lastLoginTime = '127912653523035916'; my $loginTime = Math::BigInt->new( $lastLoginTime ); # Based on the document above and the words taken directly from: # there are 1,000,000,000 nanoseconds in a second; # therefore, there are 10,000,000 100-nanosecond intervals in a single second (10,000,000 x 100 = 1,000,000,000). $loginTime = $loginTime / (60 * 10000000 ); # 60 seconds in a minute! # And because there are 1,440 minutes in every 24-hour day, this line of code tells us how many days have elapsed: $loginTime = $loginTime / 1440; # and now, to get the date of the last login: my ($year,$month,$day) = Add_Delta_Days( 1601, 1, 1, $loginTime ); print "$year-$month-$day\n"; __END__