VBS program bulk disables domain users and then moves to the specified OU

Source: Internet
Author: User
Tags ldap create domain

As a large company IT management staff, the most painful is to create, disable, delete the dozens of people user information, currently we through the program batch create domain users, but the separation of the user's relevant information to disable and delete, we need to manually complete, before the file introduced, We use PowerShell to disable and move the specified user to the specified OU, and today we are using VBS to disable and move the specified user to the specified OU.

We first need to look at the runtime environment, we create the DSGRD object organizational unit, then create the Domain Users secondary organizational unit under that organizational unit, and then create a test user.

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://img1.51cto.com/attachment/201410/30/451336_1414646042elJL.png "height=" 507 "/>

We want to disable the user after moving to the specified OU: Disable Accounts

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://img1.51cto.com/attachment/201410/30/451336_1414646042aF3C.png "height=" 508 "/>

Next we edit the program:

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://img1.51cto.com/attachment/201410/30/451336_1414646043cwK8.png "height=" 677 "/>

Code:

' ========================================================================== '  VBScript Source  file -- created with sapien technologies primalscript 3.1 '  NAME:   '  AUTHOR: Windows  user  , 12345 '  date  : 2014/10/29 '   comment:  ' ==========================================================================strdisableaccount  = TrueForReading=1strNewParentDN =  "Ou=disable accounts"       move to strcontainer =  "Ou=dsgrd object"    '  source '  ------  end configuration ---------'   Start running function set dic = createobject ("Scripting.Dictionary" ) Set  objrootdse = getobject ("LDAP://rootDSE") strdomaindn = objrootdse.get  ("defaultNamingContext")    '  dong tai huo qu yu set objcontainer  = getobject ("ldap://" &strContainer& ","  & strdomaindn) Subcontainer objcontainer,struserdnset  objfso = createobject ("Scripting.FileSystemObject") set objfile =  objFSO.OpenTextFile ("D:\11.txt",  forreading) while not objfile.atendofstream     wscript.echo vbcrlf    struserdn = trim (ObjFile.Readline)      WScript.Echo strUserDN  ' & vbcrlfif dic.exists (strUserDn)  Then  Set objcont = getobject ("ldap://" &strNewParentDN& "," & strdomaindn) ' set  Objuser = dic.item (strUserDn) If objuser.accountdisabled = true then '   wscript.echo  "account for "  & objuser.get ("cn")  &  " currently  disabled - not moved " objCont.MoveHere " ldap://"&  Objuser.distinguishedname, "cn=" &strUserDN  ' Vbnullstringelsewscript.echo  "Account currently enabled" objuser.accountdisabled =  trueobjuser.setinfo objcont.movehere  "ldap://" & objuser.distinguishedname, "CN=" & struserdn  ' vbnullstring wscript.echo  "account for "  & objuser.get ("cn")  &  " moved to new ou"      end IfEnd  Ifwendobjfile.closeset objrootdse = nothingsub subcontainer (ObjContainer,strUserDN) for  each objuser in objcontainer if regexptest ("ou=.*", objUser.name)  Then '  msgbox objuser.namesubcontainer objuser,struserdnelse dic.add objuser.samaccountname , objuser '  MsgBox  objUser.name & ":" & objUser.AccountDisabledEnd If  Next ' Set objcontainer = nothingend sub function regexptest (PATRN, STRNG)   dim regex, retval             '   build variables.   Set regEx = New RegExp          '   Establish regular expressions.   regEx.Pattern = patrn          '   Setup mode.   regEx.IgnoreCase = False          '   Sets whether case-sensitive.   retval = regex.test (strng)           '   Perform a search test.   If retVal Then    RegExpTest =True  Else     regexptest = false  end ifend function


We set up account information that needs to be disabled and moved:

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://img1.51cto.com/attachment/201410/30/451336_14146460435jE8.png "height=" 486 "/>

Then we run the program to view:

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" http:// Img1.51cto.com/attachment/201410/30/451336_1414646046pmrc.png "height=" 457 "/>

The effect of the program after execution:

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;margin:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://img1.51cto.com/attachment/201410/30/451336_1414646046BiHu.png "height="/>

This article is from the "Gao Wenrong" blog, make sure to keep this source http://gaowenlong.blog.51cto.com/451336/1569616

VBS program bulk disables domain users and then moves to the specified OU

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.