关于批量修改AD域用户的脚本

最近几天帮人弄了个脚本,是修改域用户属性的脚本,今天看到徐火军写的 关于批量修改用户属性 脚本,觉得有必要把我的成果分享给大家。什么都不说了,上脚本:

 

Dim oFSO, oTF, i
Dim sLine
Dim sLoginName

'用户批量文件
Const InpFile = "userInfo.csv"
Const ForReading = 1

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTF = oFSO.OpenTextFile(InpFile, ForReading, True)
i = 1
Do While oTF.AtEndOfStream <> True
 sLine = oTF.ReadLine
 rLine = Split(sLine,",")
 call Modifyuser(rLine(0),rLine(1),rLine(2),rLine(3),rLine(4),rLine(5),rLine(6),rLine(7),rLine(8),rLine(9),rLine(10),rLine(11),rLine(12))
 i = i + 1
Loop

Sub Modifyuser(userName,display,company,department,title,st,redmond,street,postcode,mobile,phone,fax,HomePage)
Const DomainInfo = "LDAP://dc=T,dc=net"     '这里修改为自己的域名  如: LDAP://dc=163,dc=com  本来这里可以设置为某个OU,但是考虑修改用户本就是批量任务,就直接从根开始吧,如果有需要的朋友,可以修改为自己的OU,例如:LDAP://OU=123,dc=163,dc=com
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
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
objCommand.CommandText = "SELECT distinguishedName FROM '" & DomainInfo & "' WHERE sAMAccountName='" & userName & "' or displayName='" & display & "'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
 strDN = objRecordSet.Fields("distinguishedName").Value
 Set objUser = GetObject("LDAP://" & strDN)
 objUser.Put "company",company                 '公司的名称
 objUser.Put "department",department           '职员所属部门
 objUser.Put "title",title                     '修改职员的职称
 objUser.Put "co","中国"                       '所属的国家
 objUser.Put "st",st                           '修改公司所在省州
 objUser.Put "l",redmond                       '修改公司所在城市
 objUser.Put "streetAddress",street            '修改公司地址
 objUser.Put "postalCode",postcode             '公司所在城市的邮编
 objUser.Put "mobile",mobile                   '手机
 objUser.Put "homePhone",phone                 '公司的电话
 objUser.Put "facsimileTelephoneNumber",fax    '公司的传真
 objUser.Put "wWWHomePage",HomePage            '公司的主页
 objUser.SetInfo
objRecordSet.MoveNext
Loop

end Sub

 

以下是userInfo.csv文件模板

wangkb,王侃斌,公司1,部门1,职务1,广东,深圳,福田保税区,518000,13333333333,0755-28888888,0755-28888889,http://www.EIT.com.cn

wangQQ,王茜茜,公司1,部门1,职务1,广东,深圳,福田保税区,518000,13333333333,0755-28888888,0755-28888889,http://www.EIT.com.cn

wangXQ,王熙茜,公司1,部门1,职务1,广东,深圳,福田保税区,518000,13333333333,0755-28888888,0755-28888889,http://www.EIT.com.cn

 

 

posted on 2013-05-29 16:52  自强不熄  阅读(2029)  评论(0编辑  收藏  举报