Jesin's Blog

Welcome to the Portal of Technology

  • Facebook
  • GitHub
  • RSS
  • Twitter
  • Home
  • Categories
    • Domains
    • Linux
    • Networking
    • PHP
    • Virtualization
    • Web Design
    • Web Servers
    • Windows
  • WordPress Plugins
    • Custom Error Pages
    • HTTP Digest Authentication
    • Mailgun Email Validator
  • Toolbox
    • DNS Lookup Tool
    • htdigest Generator Tool Online
    • htpasswd Generator Tool Online
    • HTTP Headers Lookup Tool
    • MD5 Encryption Tool
    • Open Port Check Tool
    • SHA-1 Encryption Tool
    • URL Encoding/Decoding Tool
  • About Me
  • Contact Me
  • Sitemap
Home ›
Windows ›
Active Directory User Creation Script

Active Directory User Creation Script

June 20, 2011 Windows Jesin A Leave a Comment

windows category thumbnail

Bulk User creation in Active Directory is made easy with the VBScript given here. Thousands of users can be created at the click of a button. Lets go step by step creating this script. Open notepad and save it by typing “create-users.vbs” INCLUDING the double quotes. This will create a file with a .vbs extension instead of .txt. Then type the following code.

set objCON = GetObject("LDAP://CN=Users, DC=example, DC=net")
Set objUser = objCON.Create("user","CN=User1")
objUser.Put "sAMAccountName", "user1"
objUser.SetInfo()

This will create an user with name “User 1” and login name “user1” in the active directory domain example.net in the Users container. By default the user account will be disabled to create account and enable them using the script itself add the following code to the end of the code above

objUser.AccountDisabled = False
objUser.SetInfo()

Now we move on to the real part of creating users in bulk. I’ll be showing you how to create 100 users with generic names like user1, user2, …. user100 using a FOR loop.

For i = 1 to 100
set objCON = GetObject("LDAP://CN=Users, DC=example, DC=net")
Set objUser = objCON.Create("user","CN=User" & i)
objUser.Put "sAMAccountName", "user" & i
objUser.SetInfo()
objUser.AccountDisabled = False
objUser.SetInfo()
Next

This will create 100 users and enable then automatically. If you want the users to be disbaled just remove the two lines above the “Next” statement. To set passwords for users add a line after the first objUser.SetInfo()

objUser.SetPassword "password"

So the final script is given below

For i = 1 to 100
set objCON = GetObject("LDAP://CN=Users, DC=example, DC=net")
Set objUser = objCON.Create("user","CN=User" & i)
objUser.Put "sAMAccountName", "user" & i
objUser.SetInfo()
objUser.AccountDisabled = False
objUser.SetPassword "password"
objUser.SetInfo()
Next

If you want to create the users inside an OU (Organizational Unit), in the GetObject function replace CN=Users with OU=OUname

Related posts:

windows category thumbnailHow to prestage a computer in Active Directory linux category thumbnailSetup Linux DNS Server for Windows Active Directory windows category thumbnailHow to setup roaming user profiles in Windows Server 2008 windows category thumbnailInternet Explorer Change User Agent php category thumbnailPHP Pie Chart Script

Tags: windows scripts, windows server

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Get a wealth of information delivered to your inbox. Subscribe and never miss a single article.

  • Tutorials and howtos
  • Code, scripts and commands
  • Online Tools

* No spam, unsubscribe anytime

Hire Me

  • SSL installation and hardening (A+ on Qualys SSL test)
  • Apache & Nginx configuration
  • Email deliverability improvement (10/10 on Mail Tester & MailGenius)
  • WordPress customization, optimization and migration
  • and much more…

    Tools

    • DNS Lookup Tool
    • htdigest Generator Tool Online
    • htpasswd Generator Tool Online
    • HTTP Headers Lookup Tool
    • MD5 Encryption Tool
    • Open Port Check Tool
    • SHA-1 Encryption Tool
    • URL Encoding/Decoding Tool

    Nav

    • Home
    • About Me
    • Contact Me
    • Privacy Policy
    • Sitemap
    Vultr SSD VPS

    Creative Commons License
    Jesin's Blog by Jesin A is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
    Based on a work at websistent.com.