This is normally what I use to get account expiry date:
#include <AD.au3>
_GetUsers()
Func _GetUsers()
_AD_Open()
If @error Then Exit MsgBox(16, "Active Directory Error", "Function _AD_Open encountered a problem. @error = " & @error & ", @extended = " & @extended)
; Search all of AD for contractors and exclude _DT accounts.
$aUserObjects = _AD_GetObjectsInOU("", "(&(objectcategory=person)(objectclass=user) (!(sAMAccountName=*_dt)(|(title=*contractor*) (title=*consultant*)(description=*contractor*) (description=*consultant*))))", 2, "sAMAccountName,accountExpires")
For $i = 0 To UBound($aUserObjects) - 1
If IsObj($aUserObjects[$i][1]) Then $aUserObjects[$i][1] = _GetADDateTime($aUserObjects[$i][1], 1)
Next
_ArrayDisplay($aUserObjects)
_AD_Close()
EndFunc ;==>_GetUsers
Func _GetADDateTime($_oADObject, $_iFlag = 0)
Local $sAD_DTStruct, $sTemp3
If $_iFlag = 1 Then
If $_oADObject.LowPart = -1 Then Return 0
If $_oADObject.LowPart > 0 And $_oADObject.HighPart > 0 Then
$sAD_DTStruct = DllStructCreate("dword low;dword high")
DllStructSetData($sAD_DTStruct, "Low", $_oADObject.LowPart)
DllStructSetData($sAD_DTStruct, "High", $_oADObject.HighPart)
$sAD_Temp = _Date_Time_FileTimeToSystemTime(DllStructGetPtr($sAD_DTStruct))
$sTemp3 = _Date_Time_SystemTimeToTzSpecificLocalTime(DllStructGetPtr($sAD_Temp))
Return _Date_Time_SystemTimeToDateTimeStr($sTemp3, 1)
EndIf
EndIf
; Convert IADsLargeInteger parts to 100ns count
$iLowPart = $_oADObject.LowPart
$iHighPart = $_oADObject.HighPart
If $iLowPart < 0 Then $iHighPart += 1; Compensate for IADsLargeInteger interface error
$iDateParts= $iHighPart * 2 ^ 32
$iDateParts+= $iLowPart
; Check if user ever logged in
If $iDateParts= 0 Then
Return "n/a"
Else
; Convert 100ns count to integer seconds
$iSeconds = Floor($iDateParts/ 10000000)
; Convert seconds since 12:00AM January 01, 1601 to date string
$sDateTime = _DateAdd("S", $iSeconds, "1601/01/01 00:00:00")
; Display result
Return $sDateTime
EndIf
EndFunc