Fala Pessoal… segue dica rápida e prática..
Precisei de um script para desbloquear um usuário no AD, e acabei encontrando este:
Caso você queira automatizar o script, basta comentar as linhas 01 e 02 e na linha 03 coloque o nome do usuário entre aspas em vez de username
username=inputbox(“Enter username:”)
if username = “” then wscript.quitldapPath = FindUser(username)
if ldapPath = “Not Found” then
wscript.echo “User not found!”
else
set objUser = getobject(ldapPath)
if isAccountLocked(objUser) then
objuser.put “lockoutTime”, 0
objUser.setinfo
wscript.echo “Account Unlocked”
else
wscript.echo “This account is not locked out”
end if
end ifFunction FindUser(Byval UserName)
on error resume nextset objRoot = getobject(“LDAP://RootDSE”)
domainName = objRoot.get(“defaultNamingContext”)
set cn = createobject(“ADODB.Connection”)
set cmd = createobject(“ADODB.Command”)
set rs = createobject(“ADODB.Recordset”)cn.open “Provider=ADsDSOObject;”
cmd.activeconnection=cn
cmd.commandtext=”SELECT ADsPath FROM ‘LDAP://” & domainName & _
“‘ WHERE sAMAccountName = ‘” & UserName & “‘”
set rs = cmd.executeif err<>0 then
wscript.echo “Error connecting to Active Directory Database:” & err.description
wscript.quit
else
if not rs.BOF and not rs.EOF then
rs.MoveFirst
FindUser = rs(0)
else
FindUser = “Not Found”
end if
end if
cn.close
end functionFunction IsAccountLocked(byval objUser)
on error resume next
set objLockout = objUser.get(“lockouttime”)if err.number = -2147463155 then
isAccountLocked = False
exit Function
end if
on error goto 0if objLockout.lowpart = 0 And objLockout.highpart = 0 Then
isAccountLocked = False
Else
isAccountLocked = True
End IfEnd Function
[divider]
Script base: http://scriptsolution.zip.net/