Search for All Users by Password Change Date

Sample script that searches Active Directory for all the users who last changed their password on October 1, 2007 or later. The pwdLastSet attribute is not replicated to the Globa

 
 
 
 
 
(0)
Add to favorites
Active Directory
8/10/2009
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Search for All Users by Password Change Date
    1 Posts | Last post September 04, 2009
    • On Error Resume Next
      
      Const ADS_SCOPE_SUBTREE = 2
      
      dtmpasswordDate = "8/8/2009"
      
      Set objShell = CreateObject("Wscript.Shell")
      lngTimeZoneBias = objShell.RegRead("HKLM\System\CurrentControlSet\Control\" _
        & "TimeZoneInformation\ActiveTimeBias")
      If UCase(TypeName(lngTimeZoneBias)) = "LONG" Then
        lngFinalBias = lngTimeZoneBias
      ElseIf UCase(TypeName(lngTimeZoneBias)) = "VARIANT()" Then
        lngFinalBias = 0
        For k = 0 To UBound(lngTimeZoneBias)
          lngFinalBias = lngFinalBias + (lngTimeZoneBias(k) * 256^k)
        Next
      End If
      
      dtmNewDate = DateAdd("n", lngFinalBias, dtmpasswordDate)
      lngSeconds = DateDiff("s", #9/1/1601#, dtmNewDate)
      strModifiedpasswordDate = CStr(lngSeconds) & "0000000"
      
      Set objConnection = CreateObject("ADODB.Connection")
      Set objCommand =   CreateObject("ADODB.Command")
      objConnection.Provider = "ADsDSOObject"
      objConnection.Open "Active Directory Provider"
      Set objCommand.ActiveConnection = objConnection
      
      objCommand.Properties("Page Size") = 1000
      objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
      
      objCommand.CommandText = _
          "SELECT Name FROM 'LDAP://dc=domain,dc=com' WHERE objectClass='user' AND objectCategory='person'"  & _
              "AND pwdLastSet>='" & strModifiedpasswordDate & "'"
              
      Set objRecordSet = objCommand.Execute
      
      objRecordSet.MoveFirst
      Do Until objRecordSet.EOF
          Wscript.Echo objRecordSet.Fields("Name").Value
          objRecordSet.MoveNext
      Loop