Assuming you have RSAT tools installed, you can use the AD module and do something like this:
# OU.csv
#
#”Name”,”Path”
#”MyNewOU1″, “DC=FABRIKAM,DC=COM”
#”MyNewOU2″, “DC=FABRIKAM,DC=COM”
#”MyNewOU3″, “DC=FABRIKAM,DC=COM”
Import-Module ActiveDirectory
Import-CSV C:\Users\rob\desktop\OU.csv | ForEach{
New-ADOrganizationalUnit -Name $_.Name -Path $_.Path -WhatIf
}
or simplify it further leveraging the values via pipeline, since the CSV has a “Name” and “Path” matching the switches you can just do this:
Import-CSV C:\Users\rob\desktop\OU.csv | New-ADOrganizationalUnit -WhatIf
either should produce this:
What if: Performing operation “New” on Target “OU=MyNewOU1,DC=FABRIKAM,DC=COM”.
What if: Performing operation “New” on Target “OU=MyNewOU2,DC=FABRIKAM,DC=COM”.
What if: Performing operation “New” on Target “OU=MyNewOU3,DC=FABRIKAM,DC=COM”.
You’ll just need to remove the -Whatif when you are ready to make the actual changes.