微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

批量修改用户密码

一个MVP写的vb代码

const ADS_ScopE_SUBTREE=2


Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 200
objCommand.Properties("Searchscope") = ADS_ScopE_SUBTREE
objCommand.CommandText = "SELECT adspath,name FROM 'LDAP://dc=shenma,dc=local' WHERE objectCategory='user' "

Set objRec = objCommand.Execute

if objRec.BOF OR objRec.EOF then
wscript.echo "不存在"
else
FOR i = 1 to objRec.RecordCount
UserPATH = objRec.Fields("adsPath").Value
set obj = Getobject(UserPATH)
obj.setpassword "111111"
obj.setinfo
wscript.echo objRec.Fields("name").Value
objRec.MoveNext
Next
wscript.echo objRec.RecordCount&"个用户成功!"
end if

-------------------------------------

需要点N次确定,很郁闷。

下面这个:

' Example VBScript to change a user's password
' ---------------------------------------------------------'
Option Explicit
Dim objOU,objUser,objRootDSE
Dim strContainer,strDNSDomain,strPassword
Dim intCounter,intAccValue,intPwdValue

' --------------------------------------------------------'
' Note: Please change OU=zjsystem,to reflect your domain
' --------------------------------------------------------'
strContainer = "OU=zjsystem,"
strPassword = "888888"
intAccValue = 544
intPwdValue = 0
intCounter = 0
' -------------------------------------------------------'
' Makes the user change H0l1d@y$ password at first logon
' -------------------------------------------------------'

Set objRootDSE = Getobject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")
strContainer = strContainer & strDNSDomain
set objOU =Getobject("LDAP://" & strContainer )

For each objUser in objOU
If objUser.class="user" then
objUser.SetPassword strPassword
objUser.SetInfo
objUser.Put "pwdLastSet",intPwdValue
objUser.SetInfo

objUser.Put "userAccountControl",intAccValue
objUser.SetInfo
intCounter = intCounter +1
End if
next

WScript.Echo strPassword & " is Password. UserAccountValue = " _
& intAccValue & vbCr & intCounter & " accounts changed"
WScript.Quit

' End of change password example VBScript
--------------

在测试机上通过了,在真实环境没有通过。不知道怎么回事,唉,对VB不熟呀

---

我吃过这个亏,慎用。

原文地址:https://www.jb51.cc/vb/262921.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐