title: How to convert Active Directory pwdLastSet to Date/Time
body: <pre><code>    public static string GetProperty(SearchResult searchResult, string PropertyName)
      {
          if (searchResult.Properties.Contains(PropertyName))
          {
              return searchResult.Properties[PropertyName][0].ToString();
          }
          else
          {
              return string.Empty;
          }
      }
  </code></pre>
  
  <p>The above method works great for most Active Directory properties except those that are related to date/time such as pwdLastSet, maxPwdAge, etc.</p>
  
  <p>My question is how to I get the pwdLastSet to a human readable datetime (like 8/13/2013 or August 13, 2013, etc)</p>
  
  <p>I've tries this but it threw exceptions </p>
  
  <pre><code>public static Int64 ConvertADSLargeIntegerToInt64(object adsLargeInteger)
  {
      var highPart = (Int32)adsLargeInteger.GetType().InvokeMember("HighPart", System.Reflection.BindingFlags.GetProperty, null, adsLargeInteger, null);
      var lowPart = (Int32)adsLargeInteger.GetType().InvokeMember("LowPart", System.Reflection.BindingFlags.GetProperty, null, adsLargeInteger, null);
      return highPart * ((Int64)UInt32.MaxValue + 1) + lowPart;
  }
  </code></pre>
  
  <p>I am using the following code to get the time as an Int64</p>
  
  <pre><code>Int64 passwordLastSet = ConvertADSLargeIntegerToInt64(objResult.Properties["pwdLastSet"][0]);
  </code></pre>
  
  <p>Then I plan on using the DateTime(Int64) constructor to create a DateTime</p>