管理域 Active Directory的朋友们,特别是Windows 2000的域,默认状态下没有提供工具一次性修改多个账户的属性,比如说账户的部门啊,账户的“登录到……”啊等等,用下面这个脚本就可以很方便的修改了,这个脚本支持域范围内的遍历,也就是说,您可以对整个域实施变更账户属性的操作。
Retrieve information from the user
strDN = InputBox("Enter the DN to the container you want to be the root of the search. (Ex. OU= test,DC=Domain,DC=Com)", "Enter DN:")
strAttrib = InputBox("Enter the attribute you wish edit. (Ex. profilePath, or homeDirectory)", "Enter Attribute")
strExQuery = InputBox("Enter additional query parameters.", "Enter Query Parameters")
strNewValue = InputBox("Enter new value for the attribute.", "Enter New Value")
Create instance of the ADO object to perform AD searches
Set con = CreateObject("ADODB.Connection")
con.Provider = "ADsDSOObject"
con.Open "Active Directory Provider"Set Query syntax
Set Command = CreateObject("ADODB.Command")
Set Command.ActiveConnection = con
Command.CommandText = "<;(&(objectCategory=person)"&strExQuery&");AdsPath">LDAP://"&strDN&">;(&(objectCategory=person)"&strExQuery&");AdsPath, cn; subTree"Set rs = Command.ExecuteEdit attribs of the returned objects
While Not rs.EOF
Set User = GetObject(rs.Fields("AdsPath").Value)
Set regEx = New RegExp
regEx.Pattern = "%username%"
regEx.Global = True
regEx.IgnoreCase = True
If strNewValue = "" Then
User.PutEx ADS_PROPERTY_CLEAR, strAttrib, vbNull
Else
User.Put strAttrib, regEx.Replace(strNewValue, User.sAMAccountName)
End If
User.SetInfo
rs.MoveNext
Wend