Move computer in AD during OSD

Let’s say you want to re-image a computer in your active directory domain. But you want it to move from e.g. the Windows 7 OU to the Windows 10 OU. If the PC already exists in AD, it will not be moved even if you specify the new OU in your SCCM task sequence in the Apply Network Settings step. Instead you can use one the following methods.

PowerShell method

Thanks to Jörgen Nilsson for the lines that make this possible. I just added some error handling and logging (http://ccmexec.com/2018/03/move-the-computer-to-the-correct-ou-during-osd-ps-version/)

Insert this step after the Setup Windows and ConfigMgr step.

Command line:

Use a package for this step which contains the ComputerOUMove.ps1 file. The computer variable %OrganizationUnit% must be set in SCCM (e.g. by SoftwareCentral http://softwarecentral.com). Remember to run this step with an account which has the right permissions.

Script:

 

 

VBS method

Put these “Run Command Line” steps into your task sequence after the Setup Windows and ConfigMgr step:

Step 1)
Name: Backup COM3 reg key
Command line: REG EXPORT HKLM\Software\Microsoft\COM3 %temp%\com.reg /y

Step 2)
Name: Change COM3 value
Command line: REG ADD HKLM\Software\Microsoft\COM3 /v REGDBVersion /t REG_BINARY /d 010000 /f

Step 3)
Name: Move computer in AD
Command line: cscript.exe .\MoveClientToCorrectOU.vbs “%OrganizationUnit%”

Use a package for this step which contains the MoveClientToCorrectOU.vbs file. The computer variable %OrganizationUnit% must be set in SCCM (e.g. by SoftwareCentral http://softwarecentral.com). Remember to run this step with an account which has the right permissions.

Step 4)
Name: Restore COM3 reg key
Command line: REG IMPORT %temp%\com.reg

Step 5)
Restart Computer

 

The MoveClientToCorrectOU.vbs should look like this:

Thanks to Jakob Gottlieb Svendsen for creating this script back in 2010 (http://blog.ctglobalservices.com/scripting-development/jgs/vbscript-move-computer-object-to-another-ou-via-command-line-parameter/)

2 Comments

Join the discussion and tell us your opinion.

Boreply
2018-03-20 at 11:24

Brilliant – just what I was looking for. Thanks a lot 🙂

windowstechreply
2018-03-22 at 22:34
– In reply to: Bo

Welcome 😉

Leave a reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.