Unlock Users from Active Directory

{ Posted on Friday, January 15, 2010 at 11:52 pm by John }
Tags : , , ,
Categories : General, Tech

Adding on to my post about Extending Active Directory, here is another VBScript that can be added to your Active Directory environment to quickly unlock a user account.  If you have not done so, please read my post on Extending Active Directory Functionality first to grasp the how to add custom VBScripts to AD.

Unlock Script :

Copy the script below to a notepad document and save it as “unlock_user.vbs“, and remember to save a copy of this to your “NETLOGON” directory to your domain controller.  Doing so will replicate this VBScript to all of your other domain controllers should you have more than one in your domain.  I have attached the script in .txt form, in the event the blog’s formatting changes the appearance.  You can find the script’s link below.

Link:  Active Directory :: Unlock User

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

When you are following the steps outlined in the “Extend Active Directory Functionality” post, use the following command to add this script to your context menu.

4,&Unlock User Account,\\stevofc.com\netlogon\unlock.user.vbs

Note:  Remember to change your domain name from what is listed in RED above to match your own domain.  As always, happy scripting!


Related posts:






Trackbacks/Pingbacks

  1. [...] This post was mentioned on Twitter by askatknits, StevoFC. StevoFC said: Unlock Users from Active Directory http://is.gd/6mfRC [...]


Leave a Reply