public static string GetProperty(SearchResult searchResult, string PropertyName)
{
if (searchResult.Properties.Contains(PropertyName))
{
return searchResult.Properties[PropertyName][0].ToString();
}
else
{
return string.Empty;
}
}
Các phương pháp trên hoạt động tuyệt vời cho các thuộc tính Active Directory nhất trừ có liên quan đến ngày/giờ như pwdLastSet, maxPwdAge vvLàm thế nào để chuyển đổi Active Directory pwdLastSet to Date/Time
Câu hỏi của tôi là làm thế nào để tôi nhận được pwdLastSet đến một datetime có thể đọc được con người (như 2013/08/13 hoặc 13 tháng 8 năm 2013, vv)
tôi đã cố gắng này, nhưng nó ném ngoại lệ
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;
}
tôi u hát đoạn mã sau để có được thời gian như một Int64
Int64 passwordLastSet = ConvertADSLargeIntegerToInt64(objResult.Properties["pwdLastSet"][0]);
Sau đó, tôi có kế hoạch sử dụng DateTime (Int64) constructor để tạo ra một DateTime