by on February 10, 2015, in

Creating Realistic Test User Accounts in Active Directory

When you need to simulate a real Active Directory with thousands of users you quickly find that creating realistic test accounts is not trivial. Sure enough, you can whip up a quick PowerShell one-liner that creates any number of accounts, but what if you need real first and last names? Real (existing) addresses? Postal codes matching phone area codes? I could go on. The point is that you need two things: input files with names, addresses etc. And script logic that creates user accounts from that data. This blog post provides both.

Mission Statement

The purpose of the script is to create an arbitrary number of user accounts with the following properties:

  • Logon name (sAMAccountName)
  • User principal name (UPN)
  • First name
  • Last name
  • Display name
  • E-mail address
  • Street
  • City
  • Postal code
  • State
  • Country
  • Phone number
  • Company
  • Department
  • Title

The accounts should be created in a specified OU; they should have a password and be enabled. The end result should look like this:

Active directory user accounts created by the PowerShell script

Realism

In order to create realistic results we need data, lists: male names, female names, surnames, addresses and a mapping between postal and phone area codes. The script CreateDemoUsers.ps1 expects separate CSV files for each of these. For Germany I have compiled the necessary lists, they can be downloaded here.

If you want your users to “live” in another country you need to provide the lists yourself.

Using CreateDemoUsers.ps1

Running the script is simple enough: just start it, there are no commandline parameters. I have run it directly on my lab’s domain controller but it should work from a domain member, too.

Before you execute the script you might want to configure a few things, though. Take a look at the global variables section at the head of the script:

#
# Global variables
#
# User properties
$ou = "OU=Users,OU=Test,OU=HK,DC=hk,DC=test" # Which OU to create the user in
$initialPassword = "Password123"             # Initial password set for the user
$orgShortName = "AC"                         # This is used to build a user's sAMAccountName
$dnsDomain = "acme.com"                      # Domain is used for e-mail address and UPN
$company = "ACME Corp."                      # Used for the user object's company attribute
$departments = (                             # Departments and associated job titles to assign to the users
                  @{"Name" = "Finance & Accounting"; Positions = ("Manager", "Accountant", "Data Entry")},
                  @{"Name" = "Human Resources"; Positions = ("Manager", "Administrator", "Officer", "Coordinator")},
                  @{"Name" = "Sales"; Positions = ("Manager", "Representative", "Consultant")},
                  @{"Name" = "Marketing"; Positions = ("Manager", "Coordinator", "Assistant", "Specialist")},
                  @{"Name" = "Engineering"; Positions = ("Manager", "Engineer", "Scientist")},
                  @{"Name" = "Consulting"; Positions = ("Manager", "Consultant")},
                  @{"Name" = "IT"; Positions = ("Manager", "Engineer", "Technician")},
                  @{"Name" = "Planning"; Positions = ("Manager", "Engineer")},
                  @{"Name" = "Contracts"; Positions = ("Manager", "Coordinator", "Clerk")},
                  @{"Name" = "Purchasing"; Positions = ("Manager", "Coordinator", "Clerk", "Purchaser")}
               )
$phoneCountryCodes = @{"DE" = "+49"}         # Country codes for the countries used in the address file

# Other parameters
$userCount = 5000                            # How many users to create
$locationCount = 20                          # How many different offices locations to use

# Files used
$firstNameFileMale = "Firstnames-m.txt"      # Format: FirstName
$firstNameFileFemale = "Firstnames-f.txt"    # Format: FirstName
$lastNameFile = "Lastnames.txt"              # Format: LastName
$addressFile = "Addresses.txt"               # Format: City,Street,State,PostalCode,Country
$postalAreaFile = "PostalAreaCode.txt"       # Format: PostalCode,PhoneAreaCode

There you can configure important things like how many users to create, which OU to create them in, how many different addresses to use and many other things. That section also contains the names of the data files the script requires. If you use my files you do not need to change anything, but if you create your own files you might want to make sure the file names match.

Script Output

When you run the script it prints the users as it creates them. That looks like this:

Created user #1, Aloysia Dittmer, AC755546, Purchaser, Purchasing, Potsdamer Str 51-53, Ludwigsfelde
Created user #2, Edelfriede Moor, AC476675, Engineer, Planning, Poststr 4, Reken
Created user #3, Rosegret Opitz, AC227159, Clerk, Contracts, Kirchenstr 15, Eppelborn
Created user #4, Ishilde Kühner, AC692150, Data Entry, Finance & Accounting, Schandauer Str 23B, Dresden
Created user #5, Aline Kutscher, AC804384, Manager, Marketing, Gütersloher Str 29, Harsewinkel
Created user #6, Anfriede Wendler, AC781922, Manager, Human Resources, Gütersloher Str 29, Harsewinkel
Created user #7, Reinbert Tietz, AC753100, Representative, Sales, Dorfstr 12, Bodnegg
Created user #8, Gottlieb Sasse, AC568118, Manager, Engineering, Rotkamp 2-6, Berlin
Created user #9, Christhild Bohm, AC328281, Clerk, Contracts, Violenstr 27, Bremen
Created user #10, Gismar Assmann, AC378428, Engineer, Engineering, Wolftalstr 24, Oberwolfach
Created user #11, Margreth Frick, AC847917, Technician, IT, Strasse Des Friedens 22A, Nesse-Apfelstädt
Created user #12, Wendelinus Steinberg, AC106453, Clerk, Contracts, Am Hohen Weg 30, Frankfurt
Created user #13, Otti Teuber, AC821496, Administrator, Human Resources, Schandauer Str 23B, Dresden
Created user #14, Wolfdieter Kober, AC964364, Officer, Human Resources, Am Hohen Weg 30, Frankfurt
Created user #15, Amalie Kugel, AC672882, Coordinator, Purchasing, Violenstr 27, Bremen
Created user #16, Arwid Scheffler, AC144555, Manager, IT, Am Hohen Weg 30, Frankfurt
Created user #17, Irmelie Nowack, AC275740, Manager, Human Resources, Potsdamer Str 51-53, Ludwigsfelde
Created user #18, Hanswilhelm Retzlaff, AC980763, Engineer, Engineering, Violenstr 27, Bremen
Created user #19, Grimbert Kipp, AC875805, Engineer, Planning, Rathausstr 6, Stutensee
Created user #20, Sieghardt Kühl, AC511142, Manager, Human Resources, Hauptstr 34, Waldburg
Created user #21, Falko Westhoff, AC384067, Officer, Human Resources, Kirchenstr 15, Eppelborn
Created user #22, Remigius Möser, AC392755, Manager, Contracts, Bahnhofstr 20, Wilhermsdorf
Created user #23, Caterina Kling, AC476422, Consultant, Consulting, Strasse Des Friedens 22A, Nesse-Apfelstädt
Created user #24, Kunigunde Sohn, AC788534, Manager, Contracts, Poststr 4, Reken
Created user #25, Charlotte Haag, AC190643, Manager, Consulting, Poststr 1, Traben-Trarbach
Created user #26, Ermenfried Schrage, AC857287, Engineer, IT, Schandauer Str 23B, Dresden
Created user #27, Steven Gebel, AC178850, Engineer, Planning, Schandauer Str 23B, Dresden
Created user #28, Hildmar Lotz, AC771875, Coordinator, Contracts, Markt 2, Schönewalde
Created user #29, Eginhard Kästner, AC365204, Data Entry, Finance & Accounting, Kirchenstr 15, Eppelborn
Created user #30, Bianka Baltes, AC880985, Manager, Consulting, Poststr 4, Reken
Created user #31, Ulrich Hölzer, AC347692, Manager, Marketing, Dorfstr 12, Bodnegg
Created user #32, Alice Friedl, AC208824, Manager, Contracts, Hauptstr 34, Waldburg
Created user #33, Engelmar Janzen, AC666387, Representative, Sales, In Der Aue 8, Plaue
Created user #34, Harriet Storm, AC599088, Representative, Sales, Kirchenstr 15, Eppelborn
Created user #35, Gerhard Krüger, AC676426, Manager, Planning, Am Hohen Weg 30, Frankfurt
Created user #36, Alla Preiß, AC211762, Engineer, Planning, Schandauer Str 23B, Dresden

Download

As the script is a little bit long for printing it here I have made it available for download.

You might also want to check out an extended version of the script which is maintained by Rob Bridgeman on GitHub.

Have fun!

Previous Article Thoughts on Cloud File Synchronization Security
Next Article VMware vExpert Award