As promised in a previous blog post here is a script to move a computer to the correct OU from within the host operating system.
There are two situations where I find this script useful:
- When a computer object already exists in Active Directory for the computer you are deploying. In this situation the existing computer object will be reused and the computer will remain in the original computer objects OU.
- When you are using a Staging OU during deployment. In this situation the computer is added to a staging OU when it is joined to the domain.
In both of these situations I want to ensure that the computer is in the correct OU when the deployment is finished.
To implement the script follow the steps detailed below:
Update the deployment point rules
The script uses the MACHINEOBJECTOU property specified using BDD rules to determine the OU that the computer object should be moved too. You will need to ensure that your rules specify a value for this property for each computer.
The following properties to be declared in the deployment point rules. These properties are used to connect to AD and move the computers. The account used must have the rights to create and delete computer objects in the domain:
Update the scripts folder
Next you must add the script to the .\distribution\scripts folder. You will notice that the script names have the prefix “Z-” this is because BDD automatically copies all scripts that start with “Z” from the distribution share to other deployment points when they are updated.
Update the build task sequence
The next thing you do is add the scripts to the build task sequence. I would recommend creating an application for each script that executes a script and then add it to the task sequence as shown below. it is important to note that the “Move Computer” task is run near the end of the State Restore phase, particularly if you are moving the computer from a staging OU.
Update your deployment points
Finally you should update your deployment points to so that these changes are propagated to the correct places.
If you want to see how to move the computer to a staging OU from within windows PE then refer to my previous blog post.