I am trying to convert AD maxpwdAge (a 64-bit integer) into a number of days.
Uses the IADs interface’s
Getmethod to retrieve the value of the domain’smaxPwdAgeattribute (line 5).Notice we use the
Setkeyword in VBScript to initialize the variable namedobjMaxPwdAge—the variable used to store the value returned byGet. Why is that?When you fetch a 64-bit large integer, ADSI does not return one giant scalar value. Instead, ADSI automatically returns an
IADsLargeIntegerobject. You use theIADsLargeIntegerinterface’sHighPartandLowPartproperties to calculate the large integer’s value. As you may have guessed,HighPartgets the high order 32 bits, andLowPartgets the low order 32 bits. You use the following formula to convertHighPartandLowPartto the large integer’s value.
The existing code in VBScript from the same page:
Const ONE_HUNDRED_NANOSECOND = .000000100 ' .000000100 is equal to 10^-7 Const SECONDS_IN_DAY = 86400 Set objDomain = GetObject("LDAP://DC=fabrikam,DC=com") ' LINE 4 Set objMaxPwdAge = objDomain.Get("maxPwdAge") ' LINE 5 If objMaxPwdAge.LowPart = 0 Then WScript.Echo "The Maximum Password Age is set to 0 in the " & _ "domain. Therefore, the password does not expire." WScript.Quit Else dblMaxPwdNano = Abs(objMaxPwdAge.HighPart * 2^32 + objMaxPwdAge.LowPart) dblMaxPwdSecs = dblMaxPwdNano * ONE_HUNDRED_NANOSECOND ' LINE 13 dblMaxPwdDays = Int(dblMaxPwdSecs / SECONDS_IN_DAY) ' LINE 14 WScript.Echo "Maximum password age: " & dblMaxPwdDays & " days" End If
How can I do this in Perl?
Endianness may come into this, but you may be able to say