username=inputbox("Enter username:")
if username = "" then wscript.Quit
strNewPassword = "Passw0rd"
ldapPath = FindUser(username)
if ldapPath = "Not Found" then
wscript.echo "User not found!"
Else
' Set password
'objUser.SetPassword strNewPassword
'objUser.SetInfo ' Save Changes
If Choice = username Then
' objUser.SetPassword (strNewPassword)
SetPassword = strNewPassword
' Display message if error changing password
If Err.Number <> 0 Then
Wscript.Echo "Unable to change password for user: " & _
objUser.sAMAccountName
Err.Clear
else
' Keep count of the number of password changes
intPasswordChanges = intPasswordChanges + 1
End If
end If
'End if
Function FindUser(Byval UserName)
on error resume next
set objRoot = getobject("LDAP://RootDSE")
domainName = objRoot.get("defaultNamingContext")
set cn = createobject("ADODB.Connection")
set cmd = createobject("ADODB.Command")
set rs = createobject("ADODB.Recordset")
'Set objUser = GetObject("LDAP://dc=india,dc=africa,dc=barclays,dc=org" & strUserDN)
cn.open "Provider=ADsDSOObject;"
cmd.activeconnection=cn
cmd.commandtext="SELECT ADsPath FROM 'LDAP://" & domainName & _
"' WHERE sAMAccountName = '" & UserName & "'"
set rs = cmd.execute
if 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 function
' Display message
wscript.echo "Finished" & vbcrlf & intPasswordChanges & _
" Passwords changed"