fortypoundhead.com

Create 5000 AD Users with VBScript

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


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

  • 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 172 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:54.211.79.150

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



Recent Forum Posts

Job Spammer: Sathya Narayana
dwirch posted on March 15, 2017 at about 7:18 in Spammers

Job Spammer: Manish Kumar
dwirch posted on March 14, 2017 at about 17:44 in Spammers

Site Migration Complete
dwirch posted on March 12, 2017 at about 11:10 in Site News

Site Migration Complete
dwirch posted on March 11, 2017 at about 0:35 in Site News

Job Spammer: Jason Weinstein
dwirch posted on March 10, 2017 at about 14:00 in Spammers

Job Spammer: Ryan Wilson
dwirch posted on March 8, 2017 at about 17:00 in Spammers