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

How can I rename a computer from the command line?

All I can find on the net is how to rename it in a domain, but I just want to rename the computer before joining a domain.

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

You can use the Win32_ComputerSystem WMI class and invoke the rename method. You can implement the WMI call in a vbscript, or powershell or however you choose to run the process.

share|improve this answer
    
I was trying to avoid WMI because it's horribly difficult to use from within .NET. It's easy from Powershell but Microsoft have made sure that we cannot be sure whether Powershell is available on all Windows machines. I hate vbscript and want it to die. –  Andrew J. Brehm Jun 16 '10 at 13:55
    
I hear you and I can appreciate that, but I have found that WMI is pretty useful and if you power through a few lines you will find you reuse a lot of the same code and can develop faster in the future when you need another script. –  BoxerBucks Jun 16 '10 at 14:16
    
Yepp. I am working on the WMI solution now. I hope it accepts an array of strings with the new name and two nothings as a paramter. –  Andrew J. Brehm Jun 16 '10 at 14:39
    
As long as you are executing it in the context of a user that has rights to do the rename and you pass "NULL" to the username and password parameters, it will work. Good luck! –  BoxerBucks Jun 16 '10 at 18:07
add comment

You can use NETDOM

NETDOM RENAMECOMPUTER %COMPUTERNAME% /NewName:%NEWNAME%

See this article

share|improve this answer
    
I don't know why this was upvoted twice. It renames a computer IN a domain. I want to rename a computer BEFORE joining a domain. –  Andrew J. Brehm Jun 17 '10 at 8:20
1  
You don't have to be a member of a domain it just provides the additional functionality that you also can when you are a member - make sens? –  CPU_BUSY Jun 17 '10 at 16:45
add comment

if your trying to rename a workstation and you want to guarantee the processes are available

wmic computersystem call rename "newname" to change a local name

wmic /node:oldname computersystem call rename "newname" for a remote name change

please note I can't test these right now but I'm sure they'll work.

share|improve this answer
    
I'll try this. I have a VM for tests. –  Andrew J. Brehm Jun 17 '10 at 8:25
    
I think it's missing the second and third parameter for "rename". How do I add two NULLs? –  Andrew J. Brehm Jun 17 '10 at 8:28
    
"","" should do it! –  tony roth Jun 17 '10 at 14:56
    
I tried two empty strings which were obviously not the same as two NULLs. Anyway, I now did the renaming thing using WMI from .NET. –  Andrew J. Brehm Jun 17 '10 at 20:25
add comment

Your Answer

 
discard

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.