2009年3月11日星期三

查找域中用户并重置密码

On Error Resume Next
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") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
'***
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Set cnvt=CreateObject("ADs.ArrayConvert")
'*****
Set objTextFile = objFSO.OpenTextFile("D:\zn\cscript\20090310\reset_password.txt", ForReading)
Password="Password@1"
setAcount=0
'*****
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
'--------------Start--------------
'If trim(strNextLine)<>"" Then
' arrUserInfo=Split(strNextLine,",")
'End If
'********
objCommand.CommandText = _
"SELECT Name,ADsPath FROM 'LDAP://dc=test,dc=com' WHERE objectCategory='user' " & _
"AND sAMAccountName='" & strNextLine & "'"
'Wscript.Echo objCommand.CommandText
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
If objRecordSet.RecordCount>0 Then
ComDNPath= objRecordSet.Fields("ADsPath")
Wscript.Echo objRecordSet.Fields("Name")
'Set objUser = GetObject(ComDNPath)
'objUser.SetPassword Password
'objUser.SetInfo
setAcount=setAcount+1
End If
objRecordSet.MoveNext
Loop
'********
'--------------End----------------
Loop
Wscript.Echo "Update Account Users:" & setAcount
objTextFile.Close
set objTextFile = Nothing

没有评论: