Have you ever had a need to generate a large number of user accounts within Active Directory and didn’t have the time to manually create them? If you are in the business of building test environments or training environments, this scenario may have happenned to you more than once in your career.
In a recent project, we had a need to create 600+ user accounts within our Active Directory domain to support a training class. I took the challenge of producing a simple and intuitive utilty that could do it for us, since I could probably code such an application much quicker than I could manually create the accounts. The end-result is the Active Directory User Creation Utility that I’m providing as part of this article. I figured others could use this as well so I wanted to provide this as a free download. The download is at the bottom of this article – feel free to give it a spin and let me know what you think. For those programmers out there that are just looking to understand how this utility was built, I’ve also provided the full source code as a separate download at the bottom of this article as well.
Double-click the CreateADUsers.exe file from the downloaded ZIP file to launch the utility. This application can be run from any domain member, it doesn’t have to be run on the Domain Controller. I believe the only requirements for use are that you should log onto your machine as a domain user that has rights to create objects within Active Directory. Your machine should also have the .NET Framework 3.5 installed.
If you have ever manually created user accounts within the Active Directory Users and Computers snap-in, the utility should be pretty self-explanatory. Just in case, the instructions for how to configure the utilty are provided below:
|Domain (NetBIOS Name)||Specify the NetBIOS name for your domain|
|Domain (Distinguished Name)||Specify the FQDN for your domain|
|User OU||Specify the Active Directory OU where you want the accounts placed. Examples:
To place within the Users OU, you can specify CN=Users;DC=mydomain;DC=com
To place within the Departments/HR OU, you can specify something like OU=HR;OU=Departments;DC=mydomain;DC=com
|Single Account or Multiple Accounts||Specify whether you looking to create a single account or multiple accounts|
|Username||If you specified a single account, this is the username for the account|
|User Prefix||If you specified multiple accounts, this is the user prefix for the accounts|
|Starting Index||If you specified multiple accounts, this is the starting index for the accounts. For example, a user prefix of User with a starting index of 1 will create the accounts User1, User2, User3,…|
|Quantity||If you specified multiple accounts, this is the number of accounts to create|
|Password Never Expires||Specify whether to enable/disable the Password Never Expires attribute on the user accounts|
|User Cannot Change Password||Specify whether to enable/disable the User Cannot Change Password attribute on the user accounts|
|Static Password or Random Password||Specify whether to define a static password across all auto-generated accounts or define a random password for each account|
|Password||If you specified a static password, this is the user-defined password for the accounts|
|Password Length||If you specified a random password, this is the number of characters to include in the password|
|Require Capital Letter||If you specified a random password, this indicates whether the random password should include at least one capital letter|
|Require Lower Case Letter||If you specified a random password, this indicates whether the random password should include at least one lower case letter|
|Require Number||If you specified a random password, this indicates whether the random password should include at least one number|
|Store username and password details in text file||Specify whether you want to place the generated account details within a text file. This is recommended if using random passwords since this will be the only way to get the passwords for those accounts|
|Text File Name||Specify the name of the text file that will contain the generated account details. The default name is Accounts.txt|
|Text File Location||Specify the location where the text file will be saved.|
When you click the Create Users button, the utility will attempt to create the requested number of accounts in the specified OU within Active Directory. If you requested a large number of accounts, it may take a few minutes. A message box will be displayed with the status of the request. An event log entry is also created with additional details and is recommended to check if you run into any issues.
If you specified random passwords for the accounts, you will definitely need to check out the Accounts.txt file that is generated so you can get the passwords for those accounts. You should record these passwords in the proper location and delete this file for security purposes
Finally, open the Active Directory Users and Computers snap-in and verify the accounts were created in the proper OU. Feel free to modify the accounts further with profile information or other details. The accounts will be easily visible since the text Auto-generated account will be shown in the description field.
Many of you may want to just incorporate this functionality into an existing application that you are building. I provided the full source code as a separate download at the bottom of this article. It’s a Visual Studio 2008 project. If you just wanted to skim the source code, here’s the key code snippets to look at. I’m leveraging the PrincipalContext and UserPrincipal objects provided in the .NET Framework 3.5 library to communicate with Active Directory.
Here are the includes for the project:
Here is the function that creates the Active Directory accounts:
Here is the function that generates the random password:
The utility and full source code are provided below:
Ask-the-Architect Site: http://community.citrix.com/p/product-automation#home
Follow Me on twitter: http://twitter.com/citrixedy