Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Alright so not sure if this is entirely possible all in one.

Situation: Brand new computer not on the domain, just a local workgroup. Want to change that computers name, join a domain, and put the computer name in a specific workgroup for that domain. This can all be done via the GUI all at once so it should be hypothetically possible via command line right?

I can rename a local computer using this method: CMD > WMIC COMPUTERSYSTEM where "Name='%computername%'" CALL Rename NEWNAME, Password, User

This works however it requires a restart for the changes to happen.

Next I made a batch file that works great to do what I want using NETDOM, however it can't be used until that computer is restarted due to the name change...

SET /P compname=[promptString]
SET /P org=[promptString]

NETDOM JOIN %compname% /Domain:DOMAIN.NET /OU:%org%,DC=DOMAIN,DC=net /UserD:DOMAIN\user /PasswordD:password /Reboot:15 /verbose

So I guess my question is... is there any way to do this in one way without having to restart? If a restart is absolutely required its too much time consumption; the only reason I want to do this VS using the windows GUI is to get it in the OU I want right away without having to pre-stage or go into AD and move the computer.

share|improve this question
Joining an Active Directory domain requires a restart. You can stage a new computer object in the OU in which it belongs, but there's no getting around a reboot at least once. –  jscott Apr 24 '12 at 22:39
What happens if you change the second command to use the %newname% instead of %computername% (after the rename of course, but no restart)? –  uSlackr Apr 24 '12 at 23:02
jscott - I realize this however through the GUI you can do both of these at the same time which is why I was assuming it would be possible to do it through cmd, wish netdom could rename the computer and join the domain all at the same time. –  toups Apr 24 '12 at 23:16
uSlackr - the second command that uses %compname% is just a variable for a user-input computer name that my batch file prompts to put in. If you put in the newcomputer name that was just named from the first command it does not recognize it as NETDOM is not doing the domain join locally but from the domain controller which that server does not recognize the new computer name until it restarts after doing the first command. –  toups Apr 24 '12 at 23:17

2 Answers 2

Perhaps split the operation into two scripts. Run the second one automatically after the reboot using a RunOnce key. The first script could automate the setting up of the second.

share|improve this answer
Yeah I've also considered this however the point of the whole thing is to do it as a one-time thing as the GUI does; rename, join the computer all in one and then restart, not restarting in-between. Real point is to make it take less time to rename, join the domain, and put the computer in the proper OU. If having to wait for a restart it would be faster to use the GUI and then connect to AD and move the computer to the proper spot =\ –  toups Apr 27 '12 at 12:24

If you set a timeout for the NETDOM command, then can you set a timeout which is ridiculously long enough for the script to also rename computer before the reboot happens? In other words, instead of having a PAUSE command after NETDOM JOIN, just put in the WMIC command after that. (Or does that smell too much like a race condition?)

share|improve this answer
Not sure how this would work, if you do netdom first then rename w/ rmic you would join under the old name not the new name you are renaming it to and that old name would be the one that is put into the correct OU in AD instead of the new one =\ –  toups Apr 26 '12 at 19:33
hmmm, good point. does execution of the WMIC command automatically and instantly reboot computer? or is there a flag to prevent that? (I'm sorry if all I'm asking are obvious questions right now, but I'm hoping that even dialoging might help you troubleshoot it). –  Alexander Bird Apr 26 '12 at 20:02
No it does not automatically restart. –  toups Apr 27 '12 at 12:25
So... Run the WMIC command, and then run NETDOM? both in the same script. Does that work? –  Alexander Bird Apr 27 '12 at 22:46
Unfortunately no, netdom connects to the DC who looks for the computer to connect to in order to perform such tasks. If you try to do netdom without restarting it can't find the computer's name since you JUST created it and haven't restarted yet so the computer doesn't actually have the new name but is still technically running under the old name. –  toups Apr 28 '12 at 2:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.