Clone OU Structure to New Domain

A quick, semi-powershell way to clone an OU structure from a source domain to a destination domain is to use the ldifde tool and then just modify the output. To generate the Output file Oustructure-cleaned.ldif we use ldifde to export all OUs and then remove the domain name (this is not necessary but helps later).

$Domain = get-addomain
ldifde -f OUStructure.ldif -d $($domain.Distinguishedname) -c `"$($domain.Distinguishedname)`" `"DC=X`" --% -r "(objectclass=organizationalUnit)" -l "ou,description,objectclass,displayName,displayNamePrintable,msCOM-UserPartitionSetLink,x121Address,uPNSuffixes,co,telexNumber,teletexTerminalIdentifier,telephoneNumber,street,st,seeAlso,searchGuide,registeredAddress,preferredDeliveryMethod,postalCode,postalAddress,postOfficeBox,physicalDeliveryOfficeName,managedBy,thumbnailLogo,l,internationalISDNNumber,facsimileTelephoneNumber,destinationIndicator,desktopProfile,defaultGroup,countryCode,c,businessCategory"

You can replace any organisation specific information (if you want your test environment to look like a different organisation)

get-content OUStructure.ldif | %{$_ -replace 'Contoso','TailSpin Toys'} | Out-file Oustructure-reOrg.ldif

Now we copy the ldif file to the target server and execute the commands to load the OU structure

$Domain = get-addomain
ldifde -i -v -k -f OUStructure.ldif  -c `"DC=X`" `"$($domain.Distinguishedname)`"