Create 5000 AD Users with VBScript

Posted On 2013-10-25 by dwirch
Tags: Scripting VBScript Tip 
Views: 1143

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
    If len(struserNumber)<4 then struserNumber=string(4-Len(struserNumber) ,"0") & struserNumber
    ' *** create the user
    set objLeaf=objcontainer.create("user", "cn=userno" & struserNumber)
' *** inform the user
wscript.echo "completed!"

What's happening

  • First, the name of the current domain is retrieved via an LDAP query.
  • Next, we set up the container where the new users are going to reside.  You can change this easily by modifying the LDAP string specified.
  • Now, a loop is started, with 5000 being the top end.  Pretty straightforward. Inside this loop, two things are accomplished.
  • Some basic string handling, which gives us a uniform length string representing the user sequence number.  This is basically a zero-padding function, with a prefix of "userno".  After that, the user is created in the container.
  • Finally, the loop is concluded, and the user is notified.

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 the Author

dwirch has posted a total of 189 articles.

Comments On This Post

No comments on this post yet!

Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.

Your IP address is:

Before you can post, you need to prove you are human. If you log in, this test goes away.

Code Links