Sure, the Group Policy Management Console Scripts released with GPMC or as a separate download has the nice scripts called CreateXMLFromEnvironment.wsf and CreateEnvironmentFromXML.wsf export and import OU/groups/GPOs between domains. But these scripts export and import much more than just the OU structure (groups, GPOs etc) and in some migration scenarios you might want to migrate/copy just the OU-structure. Here’s how you can do this using Powershell.

Make sure you have the Active Directory module for Windows PowerShell installed and run it from  Start -> Administrative Tools -> Active Directory PowerShell.

$oucsv = ‘c:\export\OUexport.csv’
Get-ADOrganizationalUnit -Filter * | export-csv $oucsv

You might want to get only from a certain base OU?

Get-ADOrganizationalUnit -Filter * -SearchBase ‘OU=test-OU,DC=ad,DC=local’ | export-csv $oucsv

Nice, so now you have a CSV-file with the structure. Here’s how to re-create them in the other domain:

$OldDom = ‘DC=ad,DC=local’
$NewDom = ‘DC=newdomain,DC=local’
$oucsv = ‘c:\export\OUexport.csv’

$success = 0
$failed = 0

$oulist = Import-Csv $oucsv
$oulist | foreach {
$outemp = $_.Distinguishedname -replace $OldDom,$NewDom
#need to split ouTemp and lose the first item
$ousplit = $outemp -split ‘,’,2
$outemp
Try {
$newOU = New-ADOrganizationalUnit -name $_.Name -path $ousplit[1] -EA stop
Write-Host “Successfully created OU: $_.Name”
$success++
}
Catch {
Write-host “ERROR creating OU: $outemp” #$error[0].exception.message”
$failed++
}
Finally {
echo “”
}

}
Write-host “Created $success OUs with $failed errors”

Thanks to uSlackr for the details.