Loading ...
Sorry, an error occurred while loading the content.
 

Calculating Password Expiration

Expand Messages
  • mllam_98
    I am trying to hit ad and determine whose accounts expire in say 15 days. I don t think the code is working, it never brings back more than 1 user. Any help or
    Message 1 of 1 , Feb 2, 2004
      I am trying to hit ad and determine whose accounts expire in say 15
      days. I don't think the code is working, it never brings back more
      than 1 user. Any help or sample code to help me do this would be
      appreciated this is a vb.net application. Here is the code I am using
      Dim xxxx As Long = DateTime.Now.Subtract(TimeSpan.FromDays
      (45)).ToFileTime()
      Dim de2 As New DirectoryEntry
      ("LDAP://sssdc1.stl.net/OU=PD,ou=clayton,dc=stl,dc=net")
      Dim src2 As New DirectorySearcher("(&
      (objectCategory=Person)(objectClass=user))")

      src2.SearchRoot = de2
      src2.SearchScope = SearchScope.Subtree
      Dim res2 As SearchResult
      Dim x As SearchResultCollection = src2.FindAll
      Dim res9 As SearchResult
      Dim xcnt As Integer = x.Count
      Dim Mail As Boolean = False
      For Each res9 In x
      Mail = False
      Dim teststring As String = res9.Properties
      ("distinguishedName")(0)
      Dim de3 As New
      DirectoryEntry("LDAP://sssdc1.stl.net/" & teststring)
      Dim src3 As New DirectorySearcher("(&
      (objectCategory=Person)(objectClass=user)(pwdLastSet<=" & xxxx & "))")
      src3.SearchRoot = de3
      src3.SearchScope = SearchScope.Subtree
      Dim res3 As SearchResult
      Dim q As SearchResultCollection = src3.FindAll
      Dim email As String
      Dim accountname As String
      Dim sqlStr As String
      For Each res3 In q

      If Not res3.Properties("sAMAccountName") Is Nothing Then
      accountname &= res3.Properties("sAMAccountName")(0)
      Console.WriteLine()
      Console.WriteLine(res3.Properties("sAMAccountName"))
      Mail = True
      Else
      Mail = False
      End If

      Next
    Your message has been successfully submitted and would be delivered to recipients shortly.