public static string GetProperty(SearchResult searchResult, string PropertyName) { if (searchResult.Properties.Contains(PropertyName)) { return searchResult.Properties[PropertyName][0].ToString(); } else { return string.Empty; } }
This method is great for most Active Directory properties except those related to date / time, such as pwdLastSet, maxPwdAge, etc.
My question is how to get pwdLastSet for human reading in datetime format (e.g. 8/13/2013 or August 13, 2013, etc.).
I'm trying to do this, but he threw exceptions
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; }
I use the following code to get time as int64
Int64 passwordLastSet = ConvertADSLargeIntegerToInt64(objResult.Properties["pwdLastSet"][0]);
Then I plan to use the DateTime constructor (Int64) to create a DateTime
c # datetime active-directory largenumber
software is fun
source share