IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    [原]批量修改AD账号Account

    xuhuojun发表于 2011-09-20 14:12:06
    love 0

    在企业环境中,往往有许多因素需要修改AD登录账号名称,通过表现在:(1)AD账号与邮箱集成号两套账户变成一套,改AD登录账号;(2)AD与OA集成,改AD账户;(3)应用系统的整合,也可能会出现此种需求。下文为AD账号批量重命名方法:

    环境描述:

    域:ICSTeam.COM,父级OU: Priver

    任务:批量更改Priver下面子OU的HR下面的用户账号。

    HR账号下面有账号A,B,C,分别改成Jimmy_xu,  Miky_zhu,  Tom_lee

    第一步:在C盘下面建立一个文件叫Name.txt,内容如:

    A, jimmy_xu

    B, Miky_zhu

    C, Tom_lee

    备注:第一列为旧用户账号,第二列为变更后的用户账号

    第二步:在C盘下面建立一个脚本Rename.vbs,内容如下:

    Const ForReading = 1

    ParentDN = "OU=HR,OU=Priver,DC=ICSTeam,DC=com" ' Change this line to reflect your environment.

    strUPNSuffix = "ICSTeam.com" ' Change this line to reflect your environment.

    Set objFilesys = CreateObject("Scripting.FileSystemObject")

    Set objFileText = objFileSys.OpenTextFile("C:\Names.txt", ForReading, true)

    Do Until objFileText.AtEndOfStream '

    strText = objFileText.Readline ' Reads the Names.txt file one line at a time.

    aryText = Split(strText,",") ' Slipts each value into different cells of aryText.

    strUserOldName = aryText(0)

    strUserNewName = aryText(1)

    set objCont = GetObject("LDAP://" & ParentDN)

    objCont.MoveHere "LDAP://cn=" & strUserOldName & "," & ParentDN, "cn=" & strUserNewName

    set objUser = GetObject("LDAP://cn=" & strUserNewName & "," & ParentDN)

    objUser.Put "sAMAccountName",strUserNewName

    objUser.Put "userPrincipalName",strUserNewName & "@" & strUPNSuffix

    objUser.Put "GivenName",strUserNewName

    objUser.Put "DisplayName",strUserNewName

    objUser.SetInfo

    Loop

    WScript.Echo "Done"

    其中,红色字体,根据环境进行相应改变。
    第三步:双击执行Rename.vbs脚本,用户账户名称发生变更。

    备注:生产环境请先在局部进行测试



沪ICP备19023445号-2号
友情链接