Home > other >  How can I move a bulk of AD groups from an OU to its upper level OU?
How can I move a bulk of AD groups from an OU to its upper level OU?

Time:11-16

I have a ton of AD Groups to move from an OU to its upper level OU. The goal is to remove the "daughter" OU

Exemple : OU=Daughter,OU=Mother,DC=test,DC=fabrikam,DC=com

I found a way to move AD Objects and a way to remove AD OU.

I Have no clue how to get a list of all the groups from this daughter OU to move them in a bulk way.

CodePudding user response:

Good day

You can use this:

#Add the groups in a variable
$groups = Get-AdGroup -Filter * -Seachbase "OU=Daughter,OU=Mother,DC=test,DC=fabrikam,DC=com"

#Set the target OU in a variable
$targetOU = "OU=Mother,DC=test,DC=fabrikam,DC=com"

#Foreach loop to run the move-adobject
foreach ($group in $groups) {
    Move-AdObject -Identity $group.samaccountname -TargetPath $targetOU
}
  • Related