Rename a windows computer from the command line
I am lazy… if I can do something from the command line without grabbing the mouse I will do it. Call me old-school 😉 But my Grandpa used to say, ‘you want something done efficiently… ask a lazy person’.
The efficient way…
Here is how to rename a computer from the CLI (or command prompt, or command line depending on your preference of nomenclature) using wmic. The first part of the command is choosing the existing computername, which we can just replace with the variable of %computername%, then we pass the new name to it. Be mindful of the single quotes, if you copy/paste this be sure they are simple apostrophes ‘ and not the backtick ` under the tilde ~ key.
Windows 7 (and I think this syntax works with 8 and 10):
WMIC computersystem where caption=’%computername%’ rename ‘NewName’
Gluttons for punishment, read on…
There are quite a few pages that come up with you search for change windows computer name from command line or command prompt, and there seems to be a bit of disagreement between the answers. The command above worked for me… but maybe you like to do things the hard way… or just want to use windows script host or VBS scripts or PowerShell (I did say the hard way). If that is the case, knock yourself out with this thread from Spiceworks… it is replete with links to unnecessarily long commands to do the above. 🙂
Admittedly, PowerShell does have a really easy way to do it now, but I just feel icky using PowerShell. The command below renames the machine and immediately restarts it. Personally, I prefer to rename the machine and restart when I get around to it.
Rename-Computer -NewName NewComputerName -Restart