我有一個工作查詢,但它抓住了AD中的所有用戶,我試圖將其縮小到最後90天。問題是即使查詢運行,我也不再有任何輸出。我知道我的數學是錯誤的,並沒有脫落90天。任何人都可以提供協助嗎?VBscript過去30天沒有輸出嘗試查詢AD用戶
Dim currentDate
currentDate = DateDiff("s", CDate("1/1/1970"), Now()) * 1000#
currentDate = currentDate - 7776000000# 'Subtracts 90 days
'Does the query
objCommand.CommandText = _
"<LDAP://" & strDN & ">;" & _
"(&(objectclass=user)(objectcategory=person)(lastLogonTimestamp<=" & currentDate & "));" & _
"adspath,distinguishedname,sAMAccountName,lastLogonTimestamp,DisplayName,WhenCreated,userAccountControl;subtree"
'Output the query info
Set objRecordSet = objCommand.Execute
rngOut.CurrentRegion.Offset(2).ClearContents
While Not objRecordSet.EOF
rngOut.value = objRecordSet.Fields("DisplayName").value
Set rngOut = rngOut.Offset(0, 1)
rngOut.value = objRecordSet.Fields("sAMAccountName").value
Set rngOut = rngOut.Offset(0, 1)
rngOut.value = objRecordSet.Fields("WhenCreated").value
Set rngOut = rngOut.Offset(0, 1)
On Error Resume Next
Set objDate = objRecordSet.Fields("lastLogonTimestamp").value
If (Err.Number <> 0) Then
On Error GoTo 0
dtmDate = ""
Else
On Error GoTo 0
lngHigh = objDate.HighPart
lngLow = objDate.LowPart
If (lngLow < 0) Then
lngHigh = lngHigh + 1
End If
If (lngHigh = 0) And (lngLow = 0) Then
dtmDate = ""
Else
dtmDate = #1/1/1601# + (((lngHigh * (2^32)) _
+ lngLow)/600000000)/1440
End If
End If
rngOut.value = dtmDate
Set rngOut = rngOut.Offset(0, 1)
rngOut.value = objRecordSet.Fields("distinguishedName").value
Set rngOut = rngOut.Offset(0, 1)
Set Uservar = objRecordSet.Fields("userAccountControl")
If Uservar And 2 Then
rngOut.value = "Disabled"
rngOut.Font.ColorIndex = 3
Else
rngOut.value = "Enabled"
rngOut.Font.ColorIndex = 0
End If
Set rngOut = rngOut.Offset(1, -5)
objRecordSet.MoveNext
Wend
我有這個工作,但只有當我改變(lastLogonTimestamp<=" & currentDate & "));
到(lastLogon<=" & currentDate & "));
和我想這有什麼不顯示正確的用戶羣。誰能告訴我爲什麼?
我建議你使用[則DateDiff ](http://msdn.microsoft.com/en-us/library/xhtyw595(v = vs.84).aspx)進行日期計算。 – PatricK
@PatricK Active Directory以不同格式存儲日期,因此用於日期計算的內置工具在此處的使用受到限制。 –