How to Unlock an Account Script

A network administrator has many tasks; one of these is to monitor login activity and maintain user accounts. Using programming language, a network administrator can enable or disable, or lock, a user from accessing an account. If a user has been locked out of an account, the administrator can incorporate a script that will unlock an account so the user can get back into the account and access the data.

Instructions

    • 1

      Access the "Active Directory Users and Computers" on your computer, which is part of the larger server; this is also known as the DSA.MSC snap-in.

    • 2

      Create the following Visual Basic Script:

      Const E_ADS_PROPERTY_NOT_FOUND = -2147463155

      Set wshArguments = WScript.Arguments

      Set objUser = GetObject(wshArguments(0))

      If IsLockedOut(objUser) Then

      objUser.Put "lockouttime","0"

      objUser.SetInfo

      MsgBox "The user has been unlocked - " & objUser.sAMAccountName

      Else

      MsgBox "The user account is not locked - " & objUser.sAMAccountName

      End If

      Function IsLockedOut(objUser)

      on Error resume next

      Set objLockout = objUser.get("lockouttime")

      if Err.Number = E_ADS_PROPERTY_NOT_FOUND then

      IsLockedOut = False

      Exit Function

      End If

      On Error GoTo 0

      if objLockout.lowpart = 0 And objLockout.highpart = 0 Then

      IsLockedOut = False

      Else

      IsLockedOut = True

      End If

      End Function

      Save this script as "UNLOCK_USER.VBS" in the server's system.

    • 3

      Create this Visual Basic script:

      Const E_ADS_PROPERTY_NOT_FOUND = -2147463155

      strSummary=""

      Set wshArguments = WScript.Arguments

      Set objOU = GetObject(wshArguments(0))

      For Each objIADs in objOU

      If LCase(objIADs.Class) = "user" Then

      If IsLockedOut(objIADs) Then

      objIADs.Put "lockouttime","0"

      objIADs.SetInfo

      strSummary=strSummary & objIADs.Get("samaccountname") & vbNewLine

      End If

      End If

      Next

      If strSummary="" Then

      MsgBox "No locked users found!"

      Else

      MsgBox "The following users have been unlocked:" & vbNewLine _

      & "-------------------------------------------------" & vbNewLine & strSummary

      End If

      Function IsLockedOut(objUser)

      on Error resume next

      Set objLockout = objUser.get("lockouttime")

      if Err.Number = E_ADS_PROPERTY_NOT_FOUND then

      IsLockedOut = False

      Exit Function

      End If

      On Error GoTo 0

      if objLockout.lowpart = 0 And objLockout.highpart = 0 Then

      IsLockedOut = False

      Else

      IsLockedOut = True

      End If

      End Function

      Save this script as "UNLOCK_USERS_IN_OU.VBS."

    • 4

      Open "ADSIEdit.MSC" and navigate to the path CN=user-Display,CN=409,CN=DisplaySpecifiers,CN=Configuration,DC=dpetri,DC=net. Right-click on the user-Display object and choose "Properties." The first attribute in the list provided is "adminContextMenu"; double-click on it and add the line of script "4,&Unlock User,\\zeus\netlogon\unlock_user.vbs." Click "Add" to add the line.

    • 5

      Go back to "ADSIEdit.MSC" and go to the path CN=organizationalUnit-Display,CN=409,CN=DisplaySpecifiers,CN=Configuration,DC=dpetri,DC=net. Find the organizationalUnit-Display object, right-click on it and select "Properties." Find the organizationalUnit-Display and double-click on it. Add the following line to the attribute: "3,&Unlock Users in OU,\\zeus\netlogon\unlock_users_in_ou.vbs." Click "Add" to add the line.

    • 6

      Close "ADSIEdit.MSC" to finish the process of adding the script that will unblock the user.

Related Searches:

References

Comments

Related Ads

Featured