Automate Your Lab – Part 4 – AD OUs, Groups And Users

Table Of Contents

After you created all your infrastructure services like AD, DNS and DHCP in this part of the series we are going to add “life” to your Active Directory.
At the moment you have an empty AD like this:


After running the script it will look like this:


You can customize the structure of your AD with csv files. There are csv files for OUs, groups and users.

You can download my standard set at the end of the article. Feel free to customize them according to your needs. My csv files are optimized for an english OS! Have a look at the comments for a german OS example.

You can call the script from the command line, e.g.


Or you can edit the variables (path to the csv files etc.) in the script directly.

Creating OUs

For creating OUs you just need to enter the names for the OUs – you must not use the LDAP syntax. It’s much easier to read. As the PowerShell cmdlet New-ADOrganisationalUnit does not support creation of OUs recursively, you have to ensure that all parent OUs already exists. To accomplish that just start with the parent OU in the csv and then specify the child OUs. E.g. if you want to create the OU SQL in the path Machines/Infra this is what the csv would look like:




Creating Groups

The following fields are available in the csv:

  • Name = [Name of the group]
  • Category [Security or Distribution]
  • Scope [DomainLocal, Global or Universal]
  • Path [LDAP path to an OU;Variables will be expanded]

E.g. if you want to create the global security group CtxAdmins in the OU Groups/CTX the csv file would be the following:


The variable $Domain is specified in the script or as a parameter on the command line.

Creating Users

Basically the same as creating groups. The following fields are available:

  • Name [Name of the user]
  • Path [[LDAP path to an OU;Variables will be expanded]]
  • MemberOf [DisplayName of an AD group the user will get member of. “Domain Users” is default.]

Download Attachments

  • zip CSV
    CSV files for automating your lab with AD OUs, groups and users
    File size: 846 B

2 thoughts on “Automate Your Lab – Part 4 – AD OUs, Groups And Users

  1. Hi Dominik,

    thank you for sharing your Powershell scripts. They really help me building my lab environment.
    Just a small remark from me: executing your script on a german windows operating system does not add the user “admin” to the Domain Admins group.
    You have to manually edit the “User.csv” and change “Domain Admins” to “Domänen-Admins”.

    Then everything works like charm!


    1. Thank you Holger for your hint. I updated the info box at the beginning of the article with a note on different languages.

Leave a Reply

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