Solved

List users not logged in for longer time

Posted on 2011-03-14
4
541 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
OfficeMate Freezes on login or does not load after login credentials are input.
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

623 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