≡ Menu

Change computer name from command line

We can rename a windows computer from command line using WMIC computersystem command. Please see the command below

WMIC computersystem where caption='currentname' rename newname

Example: If the current computer name is XP-PC, to change it to Windows7-PC, we can run the below command.

wmic computersystem where caption='xp-pc' rename windows7-pc

After running the command, you need to reboot the computer to make the changes effective.

This command works on XP, Vista, Windows 7 and also on Server 2003 and Server 2008 editions. This command can also be used from a batch file to rename computer. On Vista and Windows 7, this rename command can be run only from elevated administrator command prompt. If you run it from a normal command prompt, you would get the below error.

C:\>wmic computersystem where caption='xp-pc' call rename windows7-pc
Executing (\\XP-PC\ROOT\CIMV2:Win32_ComputerSystem.Name="XP-PC")->rename()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
        ReturnValue = 5;
};
C:\>

IF you are trying to rename a computer joined to a domain, then the computer should be online when you run the command. Otherwise you would get error 1355 as below.

C:\>wmic computersystem where caption='xp-pc' rename windows7-pc
Executing (\\XP-PC\ROOT\CIMV2:Win32_ComputerSystem.Name="XP-PC")->rename()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
        ReturnValue = 1355;
};

Error 1355 means that the specified domain can’t be contacted. On successful execution of the command, the return value would be ‘0’.

23 comments… add one
  • AHMAD RAZA

    Thanks I have changed hostname through this command in CLI ……

    How to change domain name through this command ????

  • Patrick

    How can i elevate my permissions on a remote machine?

  • Jose

    Patrick, use psexec -h to simulate “Run as Administrator”.

  • Bob

    When I get a return value 1326 Windows cannot determine the user or computer name. Return value (1326).

    What do I Do?

    • Martynas

      I getting this value (1326) when trying rename client computer which is deleted from domain. Hope this helps somebody.

  • BP

    When I ran the command it returned the following:

    “Invalid Verb Switch”

    • Graham Ansell

      I also get the “Invalid Verb Switch.”

  • vidhan

    notworking at all saying Invalid Verb Switch

  • Timothy Wilson

    I believe there was an error in the command… at least on Windows 7 using remote tools I had to put single quote marks (like ‘this’ ) around the new computer name to avoid the invalid verb switch error.

  • dumi

    You cannot put (- ) when you create the PC name in that command..when I put without its working.But i don’t know why….

  • Jen

    Missing the ” around the new name, otherwise works a treat. Should be:
    WMIC computersystem where caption=’currentname’ rename ‘newname’

    • Graham Ansell

      Thanks the double quotes on the new name works :D

  • Mike

    missing “call” verb on the second command line grey box

  • anil

    here is an example that i did and was successful…
    DO NOT- put in CALL

    WMIC COMPUTERSYSTEM WHERE CAPTION=’IK-PC’ RENAME ‘ANIL-PC’

  • Luke

    I’ve elevated the command prompt and am still a ReturnValue = 5. I’m using quotes around my name. What’s going wrong?

    The PC )Win7 Enterprise) is part of a domain. I can’t seem to change it through a batch script or locally on the machine, just to see if it’d work.

    I’ve tried numerous iterations of the commands here (i.e. adding CALL before RENAME, etc) and no dice. Same thing each time.

  • Kristian

    I get ReturnValue = 0;
    Does it mean command was successful?

  • Andrei Kravtsov

    Thanks a lot!

  • abhishek

    Hi, I am looking for a command that can show the newhostname which takes place after restart. actually i am trying to write a batch file which can write the current host name in text file, then run a .vbs script, that will prompt the current hostname and ask for new hostname and again it will come on batch command and write the new hostname in same.

  • How to Change

    Thank you very much for this. Can I change win 10 name by following same way?

  • Ark

    I appreciate this, it helped me to admin a few remote machines.

  • Why always guys type wrong double quotes ?
    WMIC COMPUTERSYSTEM WHERE CAPTION=’IK-PC’ RENAME ‘ANIL-PC’
    return in WinXP Sp3 command promt
    “Unexpected switch at this level.”
    BUT: WMIC COMPUTERSYSTEM WHERE CAPTION=’IK-PC’ RENAME ‘ANIL-PC’
    return : No Instance(s) Available.
    What is correct because mycomp name is not IK-PC…
    Another tips/ correct interogations to try:
    wmic computersystem where caption=’%computername%’ get caption, UserName, Domain /format:value

    wmic computersystem where “caption like ‘%%%computername%%%'” get caption, UserName, Domain /format:value

  • Amol

    I recently purchased a new laptop for my child which ran windows 7. I ran windows update to bring the system up to date before upgrading to windows 10 but there was a problem and I had to take the machine back to the store. They did a system restore and renamed the computer incorrectly. I’ve managed to change the name of the computer using the above but when I log into my Microsoft account and look at family devices, the name of that device is still coming up with the old computer name. How can I fix this? I’d really rather not have to restore the computer yet again to set the name to what I want. Is there another way? Many thanks?

Cancel reply

Leave a Comment