We help IT Professionals succeed at work.

Script (VBS or Batch)

I am in the process of a ADMT migration. I am migrating computers as is to the new domain. However, in the domain, I would like to run a batch file or script to rename the computer accounts to the new naming convention. In addition, I would like to include if possible from a file the old computer name and the new computer name. And return a result file whether the rename was successful or not so that I can troubleshoot the computers that didn't get renamed. Please advise.
Comment
Watch Question

Krzysztof PytkoSenior Active Directory Engineer
CERTIFIED EXPERT
Top Expert 2012

Commented:
Have you considered using input file for computer migration? Then you can specify in that file the old name and new name. Nothing to do later :) After migration, your computers would have new name in the new domain

an example input file

SourceName,TargetName
oldName,newName


and ADMT syntax

admt computer /sd:aaa.com /td:bbb.com /tot:add /tff:yes /tlg:yes /tps:yes /trg:yes /tss:yes /tup:yes /tur:yes /rdl:2 /f:c:\include.txt

Open in new window


Regards,
Krzysztof

Author

Commented:
The problem with that is that, if it has to pick up a new name, it will need to dis-join from network first, then renamed, then rebooted then joined to the new name in the new domain.

That can be done all within the computer migration on the re-name without any issues?
Krzysztof PytkoSenior Active Directory Engineer
CERTIFIED EXPERT
Top Expert 2012

Commented:
Yes, it works during agent run. Of course reboot is required in this case as in standard computer rename process.

Just try with some test machine

Krzysztof

Author

Commented:
I have attached the ADMT tool example, then are you saying, in a text format, I can have my old machines and new machine name..Then would the ADMT reboot this machine 3 times to do the final rename in the new domain?

I thought, if I migrate them as is, then run a netdom scripted utility that would be faster and work, but I need a netdom script that would have an include file and give me the results as well.
Example.docx
Krzysztof PytkoSenior Active Directory Engineer
CERTIFIED EXPERT
Top Expert 2012

Commented:
yes, choose read object from input file. And there should be just 1 reboot as I remember.
I need to check that i my test environment as I'm not sure now :)

Krzysztof

Author

Commented:
Unfortunately, I won't be able to test until another 2 weeks :( so if you do it in yours that would be great.. You see.. I heard there is  only one reboot, but in a rename process, it requires two reboots so that's why I thought, if if I just migrate the machines as is with the naming convention and then do a netdom utility to do another rename.
Krzysztof PytkoSenior Active Directory Engineer
CERTIFIED EXPERT
Top Expert 2012

Commented:
Take it easy, there is no rush if you do not need it now :]
I will test that tomorrow morning and will let you know the results in short guide

Krzysztof

Author

Commented:
You are awesome :)... Thank you so much. Of course everyone wants these migrations done quickly and efficiently.

Author

Commented:
any news krzysztof..
Krzysztof PytkoSenior Active Directory Engineer
CERTIFIED EXPERT
Top Expert 2012

Commented:
Sorry, I had no chance to check that yet. I will do that as soon as possible and post an update.

Thank you in advance for understanding

Krzysztof
Krzysztof PytkoSenior Active Directory Engineer
CERTIFIED EXPERT
Top Expert 2012

Commented:
OK, I found some issues during migration computers over input file with computer name change :/ Looks like there is need to change computer names before migration :|
Let me test this deeply

Krzysztof

Author

Commented:
Yes, that's what I thought :(.. I was thinking if the computer name would be changed after migration with a netdom then that would work.

I'm just looking for the syntax to change a number of computers from an input file in a netdom command line.
Senior Active Directory Engineer
CERTIFIED EXPERT
Top Expert 2012
Commented:
I'm sorry for delayed answer, I was bussy :/
OK, let's try this way, using netdom command as you suggested

First create a plain text file with computer names. You can use for that MS Tools. On a DC in command-line type

dsquery * -filter "(objectClass=computer)" -attr name -limit 0 | find /v "name" >>c:\comps.txt

Open in new window


now, import that file into Excel and remove all computers you don't want to rename. In another column place new name for these machines and save this as text file with space as separator

Then you can simply run below query to massively rename computers

for /f "tokens=1-2" %i in (c:\comps.txt) do netdom renamecomputer %i /NewName %j /UserD:DomainAdminAccount /PasswordD:ItsPassword /Force /REBoot:1

Open in new window


but be aware! all computers will be restarted. So, please test that for some small group first

Once again, sorry for delay

Krzysztof

Author

Commented:
Thank you so much.. I will try that for sure.

Author

Commented:
I have been trying to do this on a command line on the DC

 * -filter "(objectClass=computer)" -attr name -limit 0 | find /v "name" >>c:\comps.txt

changed to C:windows\system32 and ran that command and it came back as not an internal command..

Author

Commented:
this is what i get


C:\Users\Administrator>dsquery * -filter "(objectClass=computer)" -attr name -limit 0 | find /v "name" >>c:\comps.txt

C:\Users\Administrator>1:
The system cannot find the drive specified.

Wierldy when i open up the Text file I get all the computer names.

Author

Commented:
would this be the result in the text file ?

OldName,NewName
MSPC001,MXPC001
Krzysztof PytkoSenior Active Directory Engineer
CERTIFIED EXPERT
Top Expert 2012

Commented:
Yes sure. But if you use comma (,) as separator then you need to modify a little bit the syntax

for /f "tokens=1-2 delims=," %i in (c:\comps.txt) do netdom renamecomputer %i /NewName %j /UserD:DomainAdminAccount /PasswordD:ItsPassword /Force /REBoot:1

Open in new window


the difference is that delims is defined to not use default space as separator but comma

And I'm really surprised that you saw an error and whole output was in a text file :/ Really strange

Krzysztof

Author

Commented:
I really appreciate your help. Thank you so much.
Krzysztof PytkoSenior Active Directory Engineer
CERTIFIED EXPERT
Top Expert 2012

Commented:
You're welcome :)

I hope I could help

Krzysztof

Explore More ContentExplore courses, solutions, and other research materials related to this topic.