You want to move all OUs under 'OU=OldDept,DC=contoso,DC=com' to 'OU=NewDept,DC=contoso,DC=com' using PowerShell. Which script correctly performs this operation?
hard📝 Application Q15 of 15
PowerShell - Active Directory
You want to move all OUs under 'OU=OldDept,DC=contoso,DC=com' to 'OU=NewDept,DC=contoso,DC=com' using PowerShell. Which script correctly performs this operation?
You want to move all OUs inside 'OldDept' to 'NewDept', not just rename or move 'OldDept' itself.
Step 2: Analyze each option
Get-ADOrganizationalUnit -SearchBase 'OU=OldDept,DC=contoso,DC=com' | ForEach-Object { Move-ADObject -Identity $_.DistinguishedName -TargetPath 'OU=NewDept,DC=contoso,DC=com' } gets all OUs under 'OldDept' and moves each to 'NewDept' using a loop, which is correct. Move-ADObject -Identity 'OU=OldDept,DC=contoso,DC=com' -TargetPath 'OU=NewDept,DC=contoso,DC=com' tries to move 'OldDept' itself, not its child OUs. Get-ADOrganizationalUnit -Filter * | Move-ADObject -TargetPath 'OU=NewDept,DC=contoso,DC=com' moves all OUs in the domain, not just under 'OldDept'. Rename-ADObject -Identity 'OU=OldDept,DC=contoso,DC=com' -NewName 'NewDept' renames 'OldDept' to 'NewDept', not moving child OUs.