PowerTip: Rename a Computer with PowerShell

PowerTip: Rename a Computer with PowerShell

  • Comments 10
  • Likes

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

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • 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

    $PC.Rename("SomeThing")

    This Worked!!!

  • @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

  • @chen v

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

    Sean

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

  • Nice sample, thanks for sharing.

  • 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.

  • Hi All, thanks for sharing tips. I just installed Windows 8.1 - PowerShell Rocks :)

  • @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 Domain01\Admin01 -Restart

    By default - ComputerName is localhost

  • 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="">

  • http://technet.microsoft.com/en-us/library/hh849792.aspx 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.