Search Tools Links Login

Domain change in progress, site content is moving! See this post for more info

Create 5000 AD Users with VBScript

From time to time, it might be required that large number of generic user account objects be created in an Active Directory domain.  Here is how to do it, quickly.

Why Would You Want 5000 Generic Users?

Admittedly, this doesn't happen very often.  But let's say that your testing a new automated process, or maybe doing some performance testing against an application.  You'd want to generate a large number of unique user account objects for this.

Rather than using Active Directory Users and Computers, you can just script it with VBScript.  The code is below; it's short and pretty easy to understand.

' *** get the domain name, and set the container (OU) that the
' *** new users are to be created in
set objRootDsE=Getobject ("LDAP ://rootDsE")
set objcontainer=Getobject("LDAP://cn=users," & objRootDsE.Get("DefaultNamingContext"))
For Kounter=1 to 5000
    ' *** format the number into a four character string
    strUserNumber=formatNumber(Kounter,0,0,0)
    strUserNumber=Trim(strUserNumber)
    If len(struserNumber)<4 then struserNumber=string(4-Len(struserNumber) ,"0") & struserNumber
    strUserNumber=Replace(strUserNumber,",","")
    ' *** create the user
    set objLeaf=objcontainer.create("user", "cn=userno" & struserNumber)
    objLeaf.setinfo
Next
' *** inform the user
wscript.echo "completed!"

What's happening

Not a terribly complicated script, but I have been asked for something like this at least twice, so I figured there might be someone else out there in that might find it useful.

If you have any questions or comments, please feel free to drop a message below in the comments section, or you can post a message in the forums.

About this post

Posted: 2013-10-25
By: dwirch
Viewed: 1,936 times

Categories

Tip

Scripting

Visual Basic Script (VBS)

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

Sorry. Comments are frozen for this article. If you have a question or comment that relates to this article, please post it in the appropriate forum.