19
Apr
.NET Tip: Active Directory's pwdLastSet to DateTime in C#
to get a DateTime representing the last time a user's password was changed in active directory:
IADsLargeInteger plsVal = (IADsLargeInteger) de.Properties["pwdLastSet"].Value;
long filetime = plsVal.HighPart * 4294967296 + plsVal.LowPart;
DateTime PasswordLastSet = DateTime.FromFileTime(filetime);
converted from just one of the (vb.net) tidbits i found today in a truly most excellent wrapper for active directory… just what i was looking for. That is ActiveDs.IADsLargeInteger btw.
April 21st, 2007 at 12:22 am
I noticed several entries in our directory returned a pwdLastSet value of 12/31/1600 (which is strange since Microsoft states pwdLastSet is the number of 100 nanoseconds since the following date of 1/1/1601). Anyway, is it safe to assume a value of 12/31/1600 means the password has not yet been changed by the user?
I didnt come accross any zero values.
April 21st, 2007 at 10:37 am
Tracey.. here is the 0 value I was talking about, with my code
DateTime PasswordLastSet = DateTime.FromFileTime(filetime);
string pwdLastSet = filetime == 0 ? "Never" : PasswordLastSet.ToShortDateString();