[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Clone (Copy) OU Structure

Posted on 2011-05-09
20
Medium Priority
?
4,722 Views
Last Modified: 2012-05-11
Hi THere

I'm looking at cloning our OU structure in AD.

Basically I need to create a new Top Level OU and then winthin that copy OUS from a existing OU to that one.

Example:
Current OU is Client Computers
Within that are some sub OUs
and with them more sub OUs

I wish to create a new OU called NEW Client Computers and then have the same structure that is within Client Computers

I've found the following site that explains it better http://globalknowledgeblog.com/technology/microsoft/cloning-parallel-ou-hierarchy/

However when i try to use the command dsquery ou | select-string i get an error saying its "not recognized as an Internal Or external command"

Is there another way i can do this using powershell? or can some tell me how to get the dsquery command to work

Many thakns
0
Comment
Question by:Colchester_Institute
  • 9
  • 7
  • 3
  • +1
20 Comments
 
LVL 7

Expert Comment

by:d3ath5tar
ID: 35719213
are the ds* tools installed on your os? the solution of global knowledge is pretty spot on!
0
 
LVL 1

Author Comment

by:Colchester_Institute
ID: 35719232
I can do a dsquery no problems so i assume so?
0
 
LVL 7

Expert Comment

by:d3ath5tar
ID: 35719264
And your running this in a powershell or powershellISE window? Since you can get to dsquery that points at the select-string as the next logical step which would not be accessible from a standard cmd dos window...

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:ashutoshsapre
ID: 35719266
Install the support tools for Windows Server 2003.

Windows Server 2003 Service Pack 2 32-bit Support Tools
0
 
LVL 13

Expert Comment

by:soostibi
ID: 35719276
The referenced web page uses a compination of traditional AD command line tools (dsquery) and PowerShell cmdlets (select-string). So you have to run these expressions in PowerShell window.
But if you can use Quest's Active Directory cmdlets, I can show you a complete, PowerShell-only solution.
0
 
LVL 1

Author Comment

by:Colchester_Institute
ID: 35719395
D3ath5tar was right  as I was trying to run it in a dos window.not powershell

Now when i run the command though I get told the limit of 100 has been reached (I'm not sure where i should put the -limit command)

and also i'm getting told that DSfailed directory object not found?
0
 
LVL 1

Author Comment

by:Colchester_Institute
ID: 35719401
soostibi powershell would be better if you have a solution for that
0
 
LVL 7

Expert Comment

by:d3ath5tar
ID: 35719402
in the dsquery ou change it to

dsquery ou -1000 | sele..........

0
 
LVL 7

Expert Comment

by:d3ath5tar
ID: 35719405
my bad.... -limit 1000
0
 
LVL 7

Expert Comment

by:d3ath5tar
ID: 35719410
object not found says your string doesn't match....
0
 
LVL 1

Author Comment

by:Colchester_Institute
ID: 35719423
string not matching - would that be because they are sub OUs? of the OU i've used in the select-string?
0
 
LVL 1

Author Comment

by:Colchester_Institute
ID: 35719442
also am i right in thinking this will only copy the OUS? not the objects within the OUs?
0
 
LVL 7

Expert Comment

by:d3ath5tar
ID: 35719487
correct
0
 
LVL 1

Author Comment

by:Colchester_Institute
ID: 35719807
Is that correct to both queries i made

0
 
LVL 7

Expert Comment

by:d3ath5tar
ID: 35719878
Sorry, missed your first reply!

The string only needs to be the name of the root OU you want to copy from.... nested ou's don't need to be listed. It picks those up by virtue of their location....

You are correct in thinking that only OU objects will be replicated.
0
 
LVL 13

Accepted Solution

by:
soostibi earned 2000 total points
ID: 35720131
This is a PowerShell solution. I could not test it right now, but I think it works, try it in a non-production environment.
Adjust the $sourceroot and $targetroot variables.
Add-PSSnapin Quest.ActiveRoles.ADManagement -ErrorAction silentlycontinue

$sourceroot = "OU=Managed Objects,DC=yourdomain,DC=local"
$targetroot = "OU=New,DC=yourdomain,DC=local"

Get-QADObject -Type organizationalunit -SearchRoot $sourceroot -SearchScope subtree | ?{$_.dn -ne $sourceroot} | %{
    Add-Member -InputObject $_ -MemberType noteproperty -Name level -Value ($_.dn -split ",").count -PassThru
} | Sort-Object -Property level | %{
    $parent = if($_.dn -match "[^,]+,(.*)"){$matches[1]}
    $parent = $parent -replace ([regex]::escape($sourceroot)), $targetroot
    New-QADObject -Type organizationalunit -Name $_.name -ParentContainer $parent
}

Open in new window

0
 
LVL 1

Author Comment

by:Colchester_Institute
ID: 35720296
@d3ath5star - hmmm thats strange then as I dont understand why i get the object error?

@soostibi - I'll give it a try and see how i get on.  Am i right i need to have the target root already in place?
0
 
LVL 13

Expert Comment

by:soostibi
ID: 35720773
Yes, the target should be already created in this version.
0
 
LVL 1

Author Comment

by:Colchester_Institute
ID: 35720798
@ Soostibi ok cheers
0
 
LVL 1

Author Closing Comment

by:Colchester_Institute
ID: 35753168
Solution was spot on and I now have the script for future uses
0

Featured Post

New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Transferring FSMO roles is done when an admin wants to split roles between certain Domain Controllers or the Domain Controller holding the Roles has been forcefully demoted using dcpromo / forceremoval
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question