Option Explicit
Dim objShell, lngBiasKey, lngBias, objRootDSE
Dim strDNSDomain, objCommand, objConnection
Dim strComputer, strBase, strFilter, strAttributes
Dim strQuery, objRecordSet, strCN, strPWD, strLL
Dim dtPWD, dtLL, objDate, objDate2, i
' Obtain local time zone bias from machine registry.
Set objShell = CreateObject("Wscript.Shell") lngBiasKey = objShell.RegRead("HKLM\System\CurrentControlSet\Control\" _
& "TimeZoneInformation\ActiveTimeBias")
If UCase(TypeName(lngBiasKey)) = "LONG" Then
lngBias = lngBiasKey
ElseIf UCase(TypeName(lngBiasKey)) = "VARIANT()" Then
lngBias = 0
For k = 0 To UBound(lngBiasKey)
lngBias = lngBias + (lngBiasKey(k) * 256^k)
Next
End If
' Determine DNS domain name from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
' Use ADO to search Active Directory.
Set objCommand = CreateObject("ADODB.Command") Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection
On Error Resume Next
For i = 507508 To 568608
strComputer = "PREFIX" & i & "$"
'wscript.echo strComputer & " START"
strBase = "<LDAP://" & strDNSDomain & ">"
strFilter = "(&(objectCategory=computer)(objectClass=computer)(sAMAccountName=" & strComputer & "))"
'wscript.echo strComputer & " AGAIN"
strAttributes = "cn,pwdLastSet,lastLogonTimeStamp"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
Do Until objRecordSet.EOF
strCN = objRecordSet.Fields("cn")
strPWD = objRecordSet.Fields("pwdLastSet")
strLL = objRecordSet.Fields("lastLogonTimeStamp")
Set objDate = strPWD
dtPWD = Integer8Date(objDate, lngBias)
Set objDate2 = strLL
dtLL = Integer8Date2(objDate2, lngBias)
Wscript.Echo strCN & " ; " & dtPwd & " ; " & dtLL
objRecordSet.MoveNext
Loop
objConnection.Close
strComputer = ""
Next
Function Integer8Date(objDate, lngBias)
' Function to convert Integer8 (64-bit) value to a date, adjusted for ' time zone bias.
Dim lngAdjust, lngDate, lngHigh, lngLow
lngAdjust = lngBias
lngHigh = objDate.HighPart
lngLow = objDate.LowPart
' Account for bug in IADsLargeInteger property methods.
If (lngHigh = 0) And (lngLow = 0) Then
lngAdjust = 0
End If
lngDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) _
+ lngLow) / 600000000 - lngAdjust) / 1440
Integer8Date = CDate(lngDate)
End Function
Function Integer8Date2(objDate2, lngBias)
' Function to convert Integer8 (64-bit) value to a date, adjusted for ' time zone bias.
Dim lngAdjust, lngDate, lngHigh, lngLow
lngAdjust = lngBias
lngHigh = objDate2.HighPart
lngLow = objDate2.LowPart
' Account for bug in IADsLargeInteger property methods.
If (lngHigh = 0) And (lngLow = 0) Then
lngAdjust = 0
End If
lngDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) _
+ lngLow) / 600000000 - lngAdjust) / 1440
Integer8Date2 = CDate(lngDate)
End Function