In this guide, I’m going to show you how to create bulk OUs in Active Directory using PowerShell.
Maybe you are migrating to a new domain, server, 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.
The New-ADOrganizationalUnit command
The New-ADOrganizationalUnit cmdlet creates an Active Directory organizational unit (OU).
Here is an example:
The command below will create the OU “ADPRO Users” under the path DC=ad,DC=activedirectorypro,DC=com
New-ADOrganizationalUnit -Name "ADPRO Users" -Path "DC=ad,DC=activedirectorypro,DC=com"
Before I run the command here is a screenshot of Active Directory, you can see ADPRO Users do not exist.
Now Open PowerShell ISE 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.
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 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
# This script is used for creating bulk organizational units.
# Import active directory module for running AD cmdlets
#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
-Name $name `
-path $path `
Modify line #7 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.
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.