If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.
If you use the DirectoryEntry, it marshals the value as an ADSI IADsLargeInteger type, which at runtime is a System.__ComObject. This is annoying, but you can get the value with a little interop and some data munging. This works for me: dim entry as new DirectoryEntry("LDAP://yourdn here") dim pwd as object = entry.Properties("lastLogon").Value dim pwdDate as DateTime pwdDate = DateTime.FromFileTimeUtc(GetInt64FromLargeInteger(pwd)) Function GetInt64FromLargeInteger(byval largeInteger as Object) as Int64 dim low as int32 dim high as int32 dim valBytes(7) as byte dim longInt as IADsLargeInteger = Ctype(largeInteger, IADsLargeInteger) low = longInt.LowPart high = longInt.HighPart BitConverter.GetBytes(low).CopyTo(valBytes, 0) BitConverter.GetBytes(high).CopyTo(valBytes, 4) Return BitConverter.ToInt64(valBytes, 0) End Function <ComImport(), Guid("9068270b-0939-11D1-8be1-00c04fd8d503"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsDual)> _ public interface IADsLargeInteger property HighPart as int32 property LowPart as int32 end interface
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.