mhinze.com archive

this is an archive of the old blog, ended 6/16/08





    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.

     

     

    Technorati tags: , ,

    2 Responses to “.NET Tip: Active Directory's pwdLastSet to DateTime in C#”

    1. Tracey West Says:

      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.

    2. Matt Says:

      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();

    Leave a Reply

    © 2007 mhinze.com