Thursday, January 2, 2014

AD Unlock User Account

Listing 1: Unlock.vbs

Const EVENT_SUCCESS = 0

'This code checks to see whether a user is selected and prevents use of this script without the 
snap-in.
If WScript.Arguments.Count = 0 Then
     WScript.Echo "No User Selected"
     WScript.Quit
End If

'This code converts the username to an LDAP string and sets the LockoutTime to 0.
For Each User In WScript.Arguments
objFirstPart = "LDAP://cn="

'Edit the next line to match your OU and domain structure.
objLastPart = ",ou=Users,OU=Sales,dc=Domain,dc=Com"
objLDAPNAME = objFirstPart & User & ObjLastPart
set objUser = GetObject (ObjLDAPNAME)
objUser.LockoutTime = 0
objUser.SetInfo

'This code reports that the user account has been unlocked.
wscript.echo User & " has been unlocked"

next

'This code is optional and records who used this program and when.
Set objDomain = getObject("LDAP://rootDse")
objDC = objDomain.Get("dnsHostName")
Set objSysInfo = CreateObject("ADSystemInfo")
Set objShell = Wscript.CreateObject("Wscript.Shell")
objShell.LogEvent EVENT_SUCCESS, _
    objSysInfo.Username & " used Unlock.vbs to unlock " & objLDAPNAME , objDC

No comments:

Post a Comment