I am trying to convert AD maxpwdAge
(a 64-bit integer) into a number of days.
Uses the IADs interface's
Get
method to retrieve the value of the domain'smaxPwdAge
attribute (line 5).Notice we use the
Set
keyword 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
IADsLargeInteger
object. You use theIADsLargeInteger
interface'sHighPart
andLowPart
properties to calculate the large integer's value. As you may have guessed,HighPart
gets the high order 32 bits, andLowPart
gets the low order 32 bits. You use the following formula to convertHighPart
andLowPart
to 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?