How to Rename Windows Computers and Move Them to a New Domain using Netdom

We have been busy with our Windows domain migration lately. When we first started, we did everything manually. We went to a workstation, renamed the machine and rebooted. Also, we waited until the machine booted up and moved/joined the workstation to the new domain. We had to reboot the machine again and wait for it to boot up to continue other migration tasks. This process got tedious quickly and it was very time consuming. It took about 20 minutes for the first two steps for every machine, and we had over 100 machines to migrate!

So I put on my programmer’s hat and started to look for an automatic solution. I found that the command line tool netdom on the Windows server renamed computers and moved them nicely. I could create simple batch scripts to automate the process.

First, I made a working folder on the server and created one text file and two batch files. I named the first file computers.txt. The text file  had a list of computer names to be migrated. The first column was the old name and the second column was the new name. So the file looked like this:

oldname1 newname1
oldname2 newname2
oldname3 newname3

The first batch script does renaming. It reads the list of names provided by computers.txt and calls netdom to rename the computers. I named this script batch-rename.bat. The credential here is a Domain Admin account in the old domain.

@echo off
for /f "tokens=1-2" %%A in (computers.txt) do (
  echo Rename computer from %%A to %%B
  netdom renamecomputer %%A /newname:%%B /force /reboot:60 /userd:oldadminusername /passwordd:oldadminpassword
)
pause

The second batch file, batch-move.bat, moves the computers from the old domain to the new domain. The credential provided is a Domain Admin account in the new domain

@echo off
for /f "tokens=1-2" %%A in (computers.txt) do (
  echo Move computer %%B to new domain
  netdom move %%B /domain:newdomain.mycompany.com /ou:"OU=Computers,DC=newdomain,DC=mycompany,DC=com" /userd:newadminusername /passwordd:newadminpassword /reboot:60
)
pause

Using the new process, now I only need to double click on batch-rename.bat and wait for the computers to reboot. When every computer is ready, I double click on batch-move.bat, and I am done. There was no longer a need to visit each computer and wait for account logon and logoff anymore. I was able to migrate tens of computers in less than 30 minutes.


This post may contain affiliated links. When you click on the link and purchase a product, we receive a small commision to keep us running. Thanks.


Be the first to comment

Leave a Reply