Extract Expired Accounts from AD

Home Forums Scripting General Scripting Extract Expired Accounts from AD

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    ekrengel
    Member
    #128016

    I want to try and change this script to export all the expired user account from AD into and excel file. Right now this script that I found on the web exports them to a text file, using registry keys which I never really understand…Does anyone know where to start with this?

    Dim conn, cmd, rs, user, high, low, expire, diff, shell, bKey, bias, c, expireAt, fso, outFile
    Set conn = CreateObject(“ADODB.Connection”)
    Set cmd = CreateObject(“ADODB.Command”)
    conn.provider = “adsdsoobject”
    conn.open “active directory provider”
    cmd.activeconnection = conn
    cmd.properties(“cache results”) = False
    cmd.commandtext = “;(&(objectcategory=person)(objectclass=user));accountExpires,cn,samaccountname;subtree”
    Set rs = cmd.Execute
    Set fso = CreateObject(“Scripting.FileSystemObject”)
    set outFile = fso.CreateTextFile(“ExpiredAccounts.txt”,True)
    Set shell = CreateObject(“Wscript.Shell”)
    bKey = shell.RegRead(“HKLMSystemCurrentControlSetControlTimeZoneInformationActiveTimeBias”)
    If VarType(bKey) = 3 Then
    bias = bKey
    ElseIf VarType(bKey) = 12 Then
    For c = 0 To UBound(bKey)
    bias = bias + (bKey(k)*256^k)
    Next
    End If
    outFile.WriteLine “#common name,logon name,expired at”
    Do Until rs.eof
    diff = bias
    high = rs.fields(“accountExpires”).Value.HighPart
    low = rs.fields(“accountExpires”).Value.LowPart
    If low < 0 Then high = high + 1 End If If high = 0 And low = 0 Then diff = 0 End If If ((high*2^32+low)/600000000-diff)/1440 <> 0 And ((high*2^32+low)/600000000-diff)/1440 < 1000000 Then If DateDiff("d",DateAdd("d",((high*2^32+low)/600000000-diff)/1440,#1/1/1601#),Now) > 0 Then
    outFile.WriteLine rs.fields(“cn”).value & “,” & rs.fields(“samaccountname”).value & “,” & DateAdd(“d”,((high*2^32+low)/600000000-diff)/1440,#1/1/1601#)
    End If
    End If
    rs.movenext
    Loop
    outFile.Close
    WScript.Echo “Expired accounts have been written to “”ExpiredAccounts.txt””” [/CODE][CODE]Dim conn, cmd, rs, user, high, low, expire, diff, shell, bKey, bias, c, expireAt, fso, outFile
    Set conn = CreateObject(“ADODB.Connection”)
    Set cmd = CreateObject(“ADODB.Command”)
    conn.provider = “adsdsoobject”
    conn.open “active directory provider”
    cmd.activeconnection = conn
    cmd.properties(“cache results”) = False
    cmd.commandtext = “
    ;(&(objectcategory=person)(objectclass=user));accountExpires,cn,samaccountname;subtree”
    Set rs = cmd.Execute
    Set fso = CreateObject(“Scripting.FileSystemObject”)
    set outFile = fso.CreateTextFile(“ExpiredAccounts.txt”,True)
    Set shell = CreateObject(“Wscript.Shell”)
    bKey = shell.RegRead(“HKLMSystemCurrentControlSetControlTimeZoneInformationActiveTimeBias”)
    If VarType(bKey) = 3 Then
    bias = bKey
    ElseIf VarType(bKey) = 12 Then
    For c = 0 To UBound(bKey)
    bias = bias + (bKey(k)*256^k)
    Next
    End If
    outFile.WriteLine “#common name,logon name,expired at”
    Do Until rs.eof
    diff = bias
    high = rs.fields(“accountExpires”).Value.HighPart
    low = rs.fields(“accountExpires”).Value.LowPart
    If low < 0 Then
    high = high + 1
    End If
    If high = 0 And low = 0 Then
    diff = 0
    End If
    If ((high*2^32+low)/600000000-diff)/1440 <> 0 And ((high*2^32+low)/600000000-diff)/1440 < 1000000 Then
    If DateDiff(“d”,DateAdd(“d”,((high*2^32+low)/600000000-diff)/1440,#1/1/1601#),Now) > 0 Then
    outFile.WriteLine rs.fields(“cn”).value & “,” & rs.fields(“samaccountname”).value & “,” & DateAdd(“d”,((high*2^32+low)/600000000-diff)/1440,#1/1/1601#)
    End If
    End If
    rs.movenext
    Loop
    outFile.Close
    WScript.Echo “Expired accounts have been written to “”ExpiredAccounts.txt””” [/CODE]

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.