Announcement

Collapse
No announcement yet.

SCript to disable inactive accounts in NT4

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • SCript to disable inactive accounts in NT4

    Is there any script that I can run in my NT4 domain User manager database and disable accounts that never been used for the last three months (inactive accounts).
    please assist
    Learning something new always

  • #2
    You can use VBScript to do this...

    This will disable accounts that haven't been logged on within the last 6 weeks. I haven't tested this script, but it should work, however though if you need help with it, I suggest posting in the scripting forum. Good luck.

    Code:
    DIM theDate, UserObj, Object, GroupObj, Flags, Diff, Result
    
    Const UF_ACCOUNTDISABLE = &H0002 'Set this to TRUE to enable Logging only mode - no changes will be made
    Const LogOnly = TRUE 'Point to Object containing users to check
    
    Set GroupObj = GetObject("WinNT://MYSERVER/Users")
    
    On error resume next
    
    For each Object in GroupObj.Members
    
    'Find all User Objects Within Domain Users group (ignore machine accounts)
    
    If (Object.Class = "User") and (instr(Object.Name, "$") = 0) then Set
         UserObj = GetObject(Object.ADsPath)
    
         theDate = UserObj.get("LastLogin")
    
         theDate = Left(theDate,8)
    
         theDate = cdate(theDate) 
    
         Diff = DateDiff("dd", theDate, Now) 'find difference in days between then and now
    
         If Diff >= 1 Then Flags = UserObj.Get("UserFlags") 'if 6 weeks or more then disable the account
    
              IF (Flags AND UF_ACCOUNTDISABLE) = 0 Then 'Only disable accounts if LogOnly set to FALSE
    
                   If LogOnly = FALSE Then
    
                        UserObj.Put "UserFlags", Flags OR UF_ACCOUNTDISABLE
    
                        UserObj.SetInfo
    
                   End if
    
                   strName = UserObj.Name
    
                   result = Log(strName,Diff)
    
              End If
         End If
    End If
    
    Next
    
    Set GroupObj = Nothing
    
    
    
    Function Log(User,strDate) 'Constant for Log file path
    
    CONST StrLogFile = "C:\UserMgr1.txt"
    
    Set objFS = CreateObject("Scripting.FileSystemObject")
    
    Set strTextStream = objFS.OpenTextFile(strLogFile, 8, true)
    
    strTextStream.WriteLine("Account:" & vbTab & User & vbTab & "Inactive for:"
    & vbTab & strdate & vbtab & "Weeks" & vbtab & "Disabled on:" & vbTab & Date
    & vbTab & "at:" & vbTab & Time)
    
    strTextStream.Close
    
    Set objFS = Nothing
    
    Set strTextStream = Nothing
    
    End Function
    Andrew

    ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

    Comment

    Working...
    X