[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 731
  • Last Modified:

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.
0
shoris
Asked:
shoris
  • 11
  • 9
1 Solution
 
Krzysztof PytkoActive Directory EngineerCommented:
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
0
 
shorisAuthor 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?
0
 
Krzysztof PytkoActive Directory EngineerCommented:
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
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
shorisAuthor 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
0
 
Krzysztof PytkoActive Directory EngineerCommented:
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
0
 
shorisAuthor 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.
0
 
Krzysztof PytkoActive Directory EngineerCommented:
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
0
 
shorisAuthor Commented:
You are awesome :)... Thank you so much. Of course everyone wants these migrations done quickly and efficiently.
0
 
shorisAuthor Commented:
any news krzysztof..
0
 
Krzysztof PytkoActive Directory EngineerCommented:
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
0
 
Krzysztof PytkoActive Directory EngineerCommented:
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
0
 
shorisAuthor 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.
0
 
Krzysztof PytkoActive Directory EngineerCommented:
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
0
 
shorisAuthor Commented:
Thank you so much.. I will try that for sure.
0
 
shorisAuthor 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..
0
 
shorisAuthor 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.
0
 
shorisAuthor Commented:
would this be the result in the text file ?

OldName,NewName
MSPC001,MXPC001
0
 
Krzysztof PytkoActive Directory EngineerCommented:
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
0
 
shorisAuthor Commented:
I really appreciate your help. Thank you so much.
0
 
Krzysztof PytkoActive Directory EngineerCommented:
You're welcome :)

I hope I could help

Krzysztof
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 11
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now