In this guide, you’ll learn how to move a computer object from one OU to another. This is a great step to automatically moving computers or servers to the correct group using Powershell, instead of manually moving them.
Step 1: Delegate Control of an OU in Active Directory
Before you can move a computer object to a different OU, you first need to delegate permissions to the specific user. To do that:
- Open Active Directory Users & Computers from a domain controller.
- Right-click the OU > Delegate Permissions.
- Click “Add” to add the user.
- On the Tasks to Delegate screen, click the “Create a custom task to delegate” radial.
- Click the “Only the following objects in the folder” radial.
- Check “Computer Objects.”
- Check Create Selected objects in this folder
- Check Delete selected objects in this folder.
- Check the WRITE box and click Next.
That’s it! You can now move computers objects to the specified OU from the default parent OU.
You can test this by opening ADUC on your local computer and manually moving an object. If it works, that means it’ll work once you run the Powershell script below.
Create Powershell Script to Move Computer Objects to a Different OU
By default, objects that get added to Active Directory go to the parent Computers OU:
For this example, I want newly created computer objects to move from from the default Computers OU to the Domain>Computers>Computers OU:
To do that with Powershell, you can use a script like this. It will prompt you to enter a computer name. Capitalization matters here.
$ComputerObject = Read-Host "Type computername to move" Move-ADObject –Identity "CN=$ComputerObject,CN=Computers,DC=domain,DC=com" -TargetPath "OU=Computers,OU=Computers,OU=domain,DC=domain,DC=com"
Move Computer Object from Sub OU to Different OU
If your computer object is already moved into a specific OU, and you want to move it somewhere else (such as a Disabled Computers OU), you can use a script like this:
$ComputerObject = Read-Host "Type computername to move to DisabledComputers OU" Move-ADObject –Identity "CN=$ComputerObject,OU=Computers,OU=Computers,OU=Domain,DC=domain,DC=com" -TargetPath "OU=DisabledComputers,OU=Domain,DC=domain,DC=com"
Hopefully this guide helped you learn how to move one object to another OU or group with Powershell!