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


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 = ""                      # 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


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!

, ,

19 Responses to Creating Realistic Test User Accounts in Active Directory

  1. Matthew Nichols February 11, 2015 at 15:25 #

    Hi Helge, Long time no speak.

    Might be worth adding a value to one of the properties to identify the account as a test account. With these accounts looking so realistic it may be difficult to tell them apart from real accounts when you want to remove them post setup, for instance.

    Just a thought.


    Matthew Nichols

  2. Bjorn Houben February 11, 2015 at 15:49 #

    Great post. I always used this article that uses to create user info:

  3. Gareth February 12, 2015 at 13:12 #

    Great job Helge. I love the simplicity of your blog posts. They are easy to make sense of and really add value to any IT Administrator.

  4. Steve Dolinsky February 15, 2015 at 10:17 #

    Nice post, I was able to use data to create a US version of your lists.

    Would it be okay to link to your post from my blog with US sample data? Or I can give it to you and link to me? This is really useful and makes it simple to create test users!

    • Helge Klein February 15, 2015 at 13:20 #

      Steve, you can link to my post, of course. I would also point my readers to your data. Could you share the URL?

  5. Andrew July 1, 2015 at 16:45 #

    Hi, Great script, i will add this to an article i wrote about the top active directory powershell commands and scripts

  6. Arvinder July 29, 2015 at 15:52 #

    I am getting this error:

    Created user #41, Magarete Heinemann, UP871254, Clerk, Purchasing, Bautzener Str 1-3, Niesky
    New-ADUser : The server is unwilling to process the request
    At C:\Users\Administrator\Desktop\Temp\CreateDemoUsers\CreateDemoUsers_Edited1.ps1:152 char:4
    + New-ADUser -SamAccountName $sAMAccountName -Name $displayName -Path $ou -Acco …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (CN=Fritz Hillma…=upmtest,DC=net:String) [New-ADUser], ADException
    + FullyQualifiedErrorId : ActiveDirectoryServer:0,Microsoft.ActiveDirectory.Management.Commands.NewADUser

    Please help…

    • Zane Bond December 23, 2015 at 19:22 #

      I ran into the above error, for me, it was because the OU was incorrect (Default: I didn’t change it). To easily get the Correct OU, I downloaded an LDAP browser and just copied and pasted the text from the OU I was interested in.

  7. craig May 29, 2016 at 21:25 #

    Great script! The only, small, amendment I would make is to change the error message in line 132. You see, I tried to generate my own lists and thought I could get away with using your postalareacode.txt file. Obviously, somewhere along the line your postal codes didn’t make up with what I had in my addresses.txt and I got the error message “ERROR: No country code found for $country”. I then spent some time trying to troubleshoot the link between the country code and and the phone area code I had changed in line 29. Apart from that, great stuff.

  8. Sujay Sarma November 1, 2016 at 10:58 #

    Quite an amazing script. I was looking for exactly such a thing for testing a software feature. Thank you very very very…. much! If this was a product, I would have gladly paid for it!

  9. Nando Lutgerink November 11, 2016 at 22:45 #

    Hi Helge,

    What do I do when I want to add more nationalities (country, countrycodes) in one go?

  10. Peter December 9, 2016 at 13:42 #

    Excellent base to build from, now to see if I can improve my powershell skills by:

    – Getting the description to equal the Job Title and Department
    – Put the users in a departmental OU

  11. Rob June 29, 2017 at 15:26 #

    Could i suggest changing the script so that it uses each firstname against every lastname?
    This would allow for more users to be created from the same userset. Your example data could theoretically create 25,000,000 users rather than only 5,000.
    Currently, with it picking random firstname, lastname, is that even though i have a userset of 250,000 unique names, i get clashes when creating 100,000 users.

    Otherwise, great script! Saved me a bunch of time.

    • Rob July 6, 2017 at 12:39 #

      I have actually managed to rework the script manually to be able to do this.

      Helge, would you like me to send you the updated script, and my files with 240k unique firstnames, and 117k unique lastnames?
      My edits should allow up to 2,880,000,000 unique combinations of users, and can easily be expanded upon.

      I have used this script to successfully create a AD system with 1,000,000 unique users with this script!

      • Rob July 6, 2017 at 15:13 #

        I have since increased my name count.
        I now have a file with 217,476 firstnames (I found some dupes) and a file with 891,546 last names.
        With my version of the script, this would now allow up to 193,889,857,896 unique names.

        Your only limit now is storage space! :D

Leave a Reply