' Integer8Date2.vbs ' VBScript program demonstrating an alternative method to convert ' an Integer8 attribute, such as pwdLastSet, to a date value. The ' Integer8Date2 function uses the utility w32tm.exe. ' ' ---------------------------------------------------------------------- ' Copyright (c) 2007 Richard L. Mueller ' Hilltop Lab web site - http://www.rlmueller.net ' Version 1.0 - January 22, 2007 ' Version 1.1 - December 29, 2009 - Handle invalid dates. ' ' You have a royalty-free right to use, modify, reproduce, and ' distribute this script file in any way you find useful, provided that ' you agree that the copyright owner above has no warranty, obligations, ' or liability for such use. Option Explicit Dim objUser, objPwdLastSet ' Bind to user object. Set objUser = GetObject("LDAP://cn=TestUser,ou=Sales,dc=MyDomain.dc=com") ' Retrieve pwdLastSet using IADsLargeInteger interface. ' The pwdLastSet attribute should always have a value assigned, ' but other Integer8 attributes representing dates could be "Empty". If (TypeName(objUser.pwdLastSet) = "Object") Then Set objPwdLastSet = objUser.Get("pwdLastSet") ' Convert the Integer8 value to a date and display. Wscript.Echo "PwdLastSet = " & Integer8Date2(objPwdLastSet) Else Wscript.Echo "Password never set" End If Function Integer8Date2(objDate) ' Function to convert Integer8 (64-bit) value to a date and time ' in the local time zone. Dim objShell, strCmd, lngValue, objExec, arrWork, strValue Dim lngHigh, lngLow, strWork lngHigh = objDate.HighPart lngLow = objdate.LowPart ' Account for error in IADslargeInteger property methods. If lngLow < 0 Then lngHigh = lngHigh + 1 End If lngValue = (lngHigh) * (2 ^ 32) + lngLow strValue = FormatNumber(lngValue, 0, 0, 0, 0) Set objShell = CreateObject("Wscript.Shell") strCmd = "w32tm.exe /ntte " & strValue Set objExec = objShell.Exec(strCmd) Do While objExec.Status = 0 Wscript.Sleep 100 Loop strWork = objExec.StdOut.Read(80) ' Check for invalid date. If (InStr(strWork, "not a valid") > 0) Then Integer8Date2 = "" Else arrWork = Split(strWork, " ") Integer8Date2 = arrWork(3) & " " & arrWork(4) End If End Function