1

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.

Andrew J. Brehm
  • 1,611
  • 7
  • 37
  • 57

3 Answers3

4

You can use NETDOM

NETDOM RENAMECOMPUTER %COMPUTERNAME% /NewName:%NEWNAME%

See this article

CPU_BUSY
  • 2,332
  • 17
  • 17
  • 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 08: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
2

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.

tony roth
  • 3,884
  • 18
  • 14
1

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.

BoxerBucks
  • 1,374
  • 1
  • 9
  • 19
  • 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