Thursday, March 3, 2011

VB Script to unlock user accounts - Active directory

The below VB script code can unlock the user accounts in active directory .Copy the below code and paste to notepad and save it as .vbs extension.

UserName = InputBox("Enter the user's login name that you want to unlock:")

DomainName = InputBox("Enter the domain name in which the user account exists:")

Set UserObj = GetObject("WinNT://"& DomainName &"/"& UserName &"")
If UserObj.IsAccountLocked = -1 then UserObj.IsAccountLocked = 0

If err.number = 0 Then
    Wscript.Echo "The Account Unlock Failed.  Check that the account is, in fact, locked-out."
    Wscript.Echo "The Account Unlock was Successful"
End if

1 comment:

Sitaram Pamarthi said...

With powershell it is very easy and straight forward.