スレッド: ADSIEDITを利用したログ収集 (eXperts Connection )

安納さんが投稿されているスクリプト

指定した日数より以前にパスワードを変更したユーザーを抽出するものです。
長くてすいません。

szDomain = "DC=annou,DC=com"
intDaysBefore = 30

szDateTime = DateAdd("d", 0-intDaysBefore, Now)
WScript.Echo szdatetime
lngDateTime = CDateToInt8(szDateTime)

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 20000
objCommand.CommandText = _
";" & _
"(&(objectCategory=person)(objectClass=user)" & _
"(pwdLastSet<=" & lngDateTime & "));" & _
"cn,distinguishedName,pwdLastSet;" & _
"subtree"
Set objRecordSet = objCommand.Execute
Do Until objRecordset.EOF
szDN = objRecordset.Fields("distinguishedName")
szUser = objRecordset.Fields("cn")
lngpwdLastSet = objRecordset.Fields("pwdLastSet")
dtpwsLastSet = CInt8ToDate(lngpwdLastSet)
WScript.Echo szUser & "," & dtpwsLastSet
objRecordset.MoveNext
Loop
objConnection.Close
Set objCommand = Nothing

Function CDateToInt8(szDateTime)
dtDateValue = CDate(szDateTime)
Set objShell = CreateObject("Wscript.Shell")
lngBias = TimeZoneBIOS()
dtAdjusted = DateAdd("n", lngBias, dtDateValue)
lngSeconds = DateDiff("s", #1/1/1601#, dtAdjusted)
CDateToInt8 = CStr(lngSeconds) & "0000000"
End Function

Function TimeZoneBIOS
Set objShell = CreateObject("Wscript.Shell")
szKey = "HKLM\System\CurrentControlSet\Control\" & _
"TimeZoneInformation\ActiveTimeBias"
lngBiasKey = objShell.RegRead(szKey)
If UCase(TypeName(lngBiasKey)) = "LONG" Then
lngTZBias = lngBiasKey
ElseIf UCase(TypeName(lngBiasKey)) = "VARIANT()" Then
lngTZBias = 0
For k = 0 To UBound(lngBiasKey)
lngTZBias = lngTZBias + (lngBiasKey(k) * 256^k)
Next
End If
TimeZoneBIOS = lngTZBias
End Function

Function CInt8ToDate(lngDateTime)
On Error Resume Next
lngAdjust = TimeZoneBIOS
lngHigh = lngDateTime.HighPart
lngLow = lngDateTime.LowPart
If lngLow < 0 Then lngHigh = lngHigh + 1
If (lngHigh = 0) And (lngLow = 0) Then lngAdjust = 0
lngDate = #1/1/1601# _
+ (((lngHigh * (2 ^ 32)) _
+ lngLow) / 600000000 - lngAdjust) / 1440
CInt8ToDate = CDate(lngDate)
If Err.Number <> 0 Then
On Error GoTo 0
CInt8ToDate = #1/1/1601#
End If
End Function