Microsoft Powershell – Create OU-structure based on csv-file

Release date: Desember 21st 2022

Welcome to my Microsoft Tips & Tricks section. I recently experienced a complete hardware crash in my old lab, and had to do a complete rebuild. Although this was sad, it gave me the opportunity to do it by scripting this time. This involved recreating the OU-structure in AD, as shown below.

To set up this, I first created a csv-file with “;” as the delimiter containing the following data:

  • OUName
  • OUPath

The path is the distinguishedName of the OU. Right-click, select properties, then select the attribute editor. 

Next, using the script below, I easily recreated the OU structure in AD. NOTE: The user I ran this script with had Domain Admin permissions, otherwise this wouldn’t have worked.

Import-Module activedirectory
$ADOU = Import-csv <Path to csv-file>.csv -Delimiter ";"
foreach ($ou in $ADou)
$name = $ou.OUName
$path = $ou.OUPath
New-ADOrganizationalUnit `
-Name $name `
-path $path `

Now that I had created the OU structure to my liking, I could now proceed with creating my Admin User groups, which I also did by using a script, detailed here: Create AD Admin groups based on csv-file

Big thanks to: Robert Allen’s: Create Bulk Organizational Units (OU) in Active Directory with PowerShell

Microsoft Tips & Tricks section

Disclaimer: Every tips/tricks/posting I have published here, is tried and tested in different it-solutions. It is not guaranteed to work everywhere, but is meant as a tip for other users out there. Remember, Google is your friend and don’t be afraid to steal with pride! Feel free to comment below as needed.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: