PowerTip: Rename a Computer with PowerShell

Summary: Use Windows PowerShell to rename a newly created computer.

Hey, Scripting Guy! Question How can I use Windows PowerShell to rename a computer if I don’t know the machine name?

Hey, Scripting Guy! Answer Use the Rename-Computer cmdlet and the built in HOSTNAME command, then reboot the computer. 
          For example, to rename a computer to called MININT-123 to CONTOSO-FS:

RENAME-COMPUTER –computername MININT-123 –newname CONTOSO-FS

Comments (13)

  1. Anonymous says:


    PowerShell V3 or later. – Users should learn how to use the Internet to look things up. All CmdLets are available by just pasting the CmdLet name into Google, Bing or Yahoo.

    The first thing a hopeful Admin needs to learn is how to use the search engine. It is your pal.

    Hope this helps.

  2. Anonymous says:

    Any idea what I am doing wrong with this rename command?

    RENAME-COMPUTER -computername WIN-RCKIR1484MR -newname QAMPF16SPARE

    The error message is The term ‘RENAME-COMPUTER’ is not recognized as the name of the cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    At line:1 char:16
    + RENAME-COMPUTER <<< -computername WIN-RCKIR1484MR -newname QAMPF16SPARE

  3. Chen V says:

    If I am not wrong, the system requires a reboot after rename to take effect. I am not sure. I tried

    $PC = Get-WmiObject -Class Win32_ComputerSystem


    This Worked!!!

  4. @chen v

    You are absolutely correct.  A reboot of the machine is required.

    Now to rename the computer locally if you don't know it's name in one line.

    RENAME-COMPUTER -computer name (hostname) -newname CONTOSO-FS; RESTART-COMPUTER -force

  5. @chen v

    More correctly a restart is ALWAYS required after a computer is renamed, even with WMI


  6. Yes, restart is required to effect the name change. The restart command can also be included here.

  7. Durval Ramos says:

    Nice sample, thanks for sharing.

  8. Ed Wilson says:

    On Windows 8 and above, the Rename-Computer function includes a -restart parameter so it is not necessary to also use the Restart-Computer function.

  9. Chen V says:

    Hi All, thanks for sharing tips. I just installed Windows 8.1 – PowerShell Rocks 🙂

  10. Chen V says:

    @Sean Kearney – Your code has typo

    RENAME-COMPUTER -computer name (hostname) -newname CONTOSO-FS; RESTART-COMPUTER -force

    RENAME-COMPUTER -computername (hostname) -newname CONTOSO-FS; RESTART-COMPUTER -force

    ComputerName "No Space"

    This can be done like below

    Rename-Computer -NewName PowerShell -DomainCredential Domain01Admin01 -Restart

    By default – ComputerName is localhost

  11. Frank says:

    Rename-Computer is not recognized….

  12. Mad Hatter says:

    When you run the Poweshell, RUN AS ADMINISTRATOR and try again.

  13. John9241 says:

    I know this is old but, @Frank… This was added to PowerShell 3.0, so you’re probably running an older version. If it’s not recognized, it’s probably version related. If it were related to privileges, the error would include verbiage regarding privileges.

Skip to main content