Create Bulk Organizational Units (OU) in Active Directory with PowerShell

In this guide, I’m going to show you how to create an organizational unit (OU) using PowerShell. I’ll give examples of creating a single OU and creating multiple OUs with PowerShell.

Maybe you are migrating to a new domain, or merging with another company, or creating a lab environment. Whatever the case PowerShell can be used to quickly create a bunch of OUs and save you time. 

Let’s get started. 

Create a Single Organizational Unit (OU) Using PowerShell

The New-ADOrganizationalUnit cmdlet creates an Active Directory organizational unit (OU). 

Here is an example:

The command below will create the OU “ADPRO Test Users” under the path DC=ad,DC=activedirectorypro,DC=com

New-ADOrganizationalUnit -Name "ADPRO Test Users" -Path "DC=ad,DC=activedirectorypro,DC=com"

Before I run the command here is a screenshot of Active Directory, you can see ADPRO Test Users do not exist. 

Now Open PowerShell and run the command. 

Refresh AD and the OU is now there. 

That was an example of creating a single OU with PowerShell. Now let’s look at how to create a bunch of OUs. 

Bulk Create Organizational Units (OU) using PowerShell

In this example, I’m going to create multiple OUs by using a CSV file.

Step 1: Create a CSV file with a name and path header. 

Step 2: Add the OU names under the name column and the path to where you want them created in AD. 

In the above screenshot, I’m going to create several OUs (Marketing, HR, IT, and so on) in the ADPro Test Users OU. 

The path is the distinguishedName of the OU. To find this go to the OU, right-click, select properties, then select the attribute editor. 

Step 3: Save the CSV

You can save it anywhere you want. 

Step 4:  Copy and Pase the script below into PowerShell ISE

# author: activedirectorypro.com
# This script is used for creating bulk organizational units.

# Import active directory module for running AD cmdlets
Import-Module activedirectory

#Store the data from the CSV in the $ADOU variable. 
$ADOU = Import-csv C:\it\ou.csv

#Loop through each row containing user details in the CSV file
foreach ($ou in $ADou)
{
#Read data from each field in each row and assign the data to a variable as below

$name = $ou.name
$path = $ou.path

#Account will be created in the OU provided by the $OU variable read from the CSV file
New-ADOrganizationalUnit `
-Name $name `
-path $path `

}

Modify line #8 and update the path to your CSV. I called my CSV ou.csv and saved it to the c:\it folder so my line 7 looks like this. 

Step 5. Run the script

Click the “run script” button to run the script. 

Refresh AD and you should see the newly created OUs. 

Related: Create Active Directory Groups with PowerShell

Create OUs Using the AD Pro Toolkit

The AD Pro Toolkit makes it very easy to create multiple OUs at once using a CSV template.

1. Click on Import OUs

2. Download the CSV Template and enter new OU details

  • Name = Name of the OU
  • distinguishedName = path to create the new OU in Active Directory

The included template provides an example of how to fill out the CSV.

When your template is filled out move to step 3.

3. Select CSV file and click run.

To get a report of all OUs click on OU reports.

Conclusion

In this guide, I showed you how to create a single OU and how to create bulk OUs by using the New-ADOrganizationalUnit cmdlet. I use this script to quickly rebuild my lab environment. I do a lot of testing in Active Directory so I often need to rebuild it from scratch to test new builds of the AD Pro Toolkit. This script helps to simplify the rebuild process of AD. 

Post your questions or comments below. 

2 thoughts on “Create Bulk Organizational Units (OU) in Active Directory with PowerShell”

Leave a Comment