Solved

List users not logged in for longer time

Posted on 2011-03-14
4
534 Views
Last Modified: 2012-05-11
Hi there,

I have an environment with users only working for a couple of weeks or months.
Every new user gets a new account.
After leaving the unit, the accounts used to remain untouched.
The accounts are blocked with a policy after 30 days.

Now we have the need to clean up about 250 user accounts not longer valid any more.

Is there a method to list user accounts with criteria like
- Password/Login blocked (by policy)
- last login longer than a given time

thanks for your help

Michael
0
Comment
Question by:michaellandwehr
  • 2
4 Comments
 
LVL 35

Accepted Solution

by:
Ernie Beek earned 500 total points
ID: 35127161
Well, I have a script that creates a csv file with the last logon of users. Perhaps that might help you.

 
Const FILE_OUT = "LastLogon.txt"
' Get time zone adjustment. If GMT is good enough, you can omit all this bias-related logic.
Set oShell = CreateObject("Wscript.Shell")
oBias = oShell.RegRead("HKLM\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias")
If VarType(oBias) = vbLong Then
    lBias = oBias
ElseIf VarType(oBias) = vbVariant Then
    lBias = 0
    For iByte = 0 To UBound(oBias)
        lBias = lBias * 256 + oBias(iByte)
    Next
End If
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oFile = oFS.CreateTextFile(FILE_OUT, True)
oFile.WriteLine "distinguishedName" & vbTab & "LastLogon"
Set cnAD = CreateObject("ADODB.Connection")
cnAD.Provider = "ADsDSOObject"
cnAD.Open "Active Directory Provider"
Set cmdQry = CreateObject("ADODB.Command")
Set cmdQry.ActiveConnection = cnAD
Set oRootDSE = GetObject("LDAP://RootDSE")
cmdQry.CommandText = "<LDAP://" & oRootDSE.Get("defaultNamingContext") & ">;(objectCategory=person);distinguishedName;subtree"
cmdQry.Properties("Page Size") = 500
Set rsUsers = cmdQry.Execute()
Do While Not rsUsers.EOF
    sDN = rsUsers("distinguishedName")
    Set oUser = GetObject("LDAP://" & sDN)
    sLastLogon = ""
    On Error Resume Next
    Set oLastLogon = oUser.LastLogon
    If Err = 0 Then
        lHigh = oLastLogon.HighPart
        lLow = oLastLogon.LowPart
        If lLow = 0 And lHigh = 0 Then
        Else
            If lLow < 0 Then
                lHigh = lHigh + 1 ' compensates for API quirk
            End If
            sLastLogon = FormatDateTime((#1/1/1601# + ((lHigh * 2 ^ 32 + lLow) / 600000000 - lBias) / 1440),2)
        End If
    End If
    On Error GoTo 0
    oFile.WriteLine sDN & vbTab & sLastLogon
    rsUsers.MoveNext
Loop
rsUsers.Close
cnAD.Close
oFile.Close

Open in new window

0
 
LVL 9

Expert Comment

by:Chev_PCN
ID: 35127840
Use ADFIND.

adfind -f "&(objectcategory=user)(lockouttime>=1)" -dn >>c:\a\lockout.txt
0
 

Author Comment

by:michaellandwehr
ID: 35128556
Hi erniebeek,

Your script solved my problem so far.
I only had to modify lline 43 as it was easier to sort on the date on the first position and to replace  vbTab with "," ( the  vbTab variable did not work)


    oFile.WriteLine sLastLogon & "," & sDN


Thank you very much.

Michael
0
 
LVL 35

Expert Comment

by:Ernie Beek
ID: 35129279
Glad it helped you out :)

And thx for the points.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn about cloud computing and its benefits for small business owners.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question