Get maxPwdAge for a Domain in AD.

Get Domain level directory entry with username/password, get the property value for ‘maxPwdAge‘ (which would be System.__ComObject)
Convert System.__ComObject to datetime/int.
We have to use COM Interop Libraries for this one, ActiveDs.dll (you can find it on the web)

System.Int64 largeInt=0;
IADsLargeInteger int64Val = (IADsLargeInteger) ent.Properties["maxPwdAge"].Value;
largeInt = int64Val.HighPart * 0x100000000 + int64Val.LowPart;
long ticks = Math.Abs((long)largeInt);
TimeSpan passwordAge = TimeSpan.FromTicks(ticks);
Console.WriteLine("PasswordAge={0}",passwordAge );
Console.WriteLine("PasswordAge in Days={0}", passwordAge.Days);

For more information on converting Large Integer Property Type, please check

Posted in Active Directory, C#

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: