I wrote a blog post way back(2010) on how to move a computer to another OU during OS Deployment http://ccmexec.com/2010/12/move-computer-to-the-correct-ou-during-deployment/.
Could be that you want to move it when you upgrade to Windows 10 or if you reinstall a computer and it already exist in an different OU then it will not be moved automatically. The script is still being used, downloaded and commented on. So here is an updated blog post with a PowerShell script that does the move, if you don’t want to use a webservice which there are couple of on Technet Gallery.
# Script to move the computer object in AD to the OU supplied as a variable
# 1st Example Command line Powershell.exe -NoProfile -ExecutionPolicy bypass -file MoveToOU.ps1 "%MachineObjectOU%"
# 2nd example command line Powershell.exe -NoProfile -ExecutionPolicy bypass -file MoveToOU.ps1 "OU=Desktop,OU=Computers,OU=Test,DC=Test,DC=Local"
$OU = $args
$CompDN = ([ADSISEARCHER]”sAMAccountName=$($env:COMPUTERNAME)$”).FindOne().Path
$CompObj = [ADSI]”$CompDN”
$_.Exception.Message ; Exit 1
It can be downloaded here as well: https://gallery.technet.microsoft.com/
Save the script to a file in your package source folder for the script.
- Add the script to a package you replicate to all DPs
- In the Task Sequence add the following Run Command Line task (Make sure to add it after the “Setup Windows and Configuration Manager Client step”)
- Use a User Account with permission in the Active Directory to perform the task.
In this example the %MachineObjectOU% variable is used which can be set by MDT for example.
As simple as that and you are done!
Thanks to my colleague Johan Schrewelius for the help.