How To Rename the Computer in Windows Using PowerShell (Rename-Computer Cmdlet)

change computer name windows

In this PowerShell tutorial, we will learn how to change the computer name in Windows using the Rename-Computer Cmdlet. It is a very simple and easy-to-use PowerShell command.

The Rename-Computer Cmdlet has the following syntax, where NewComputerName is the name you want to use:

Rename-Computer -NewName NewComputerName
Rename-Computer -NewName NewComputerName -Restart
Rename-Computer -ComputerName <IP/Name> -NewName NewComputerName 

The rename operation required a restart. If you use the -Restart option, it will automatically restart the computer.


In our first example, we change the computer name to Desktop-1 (the changes will only take effect after you restart the computer):

Rename-Computer -NewName Desktop-01

In the following example, we add the -Restart parameter to the Rename-Computer cmdlet. It will automatically restart the computer without giving a warning message:

Rename-Computer -NewName Desktop-01 -Restart

You can check the computer name by running the hostname command:


Changing the Name of a Remote Computer

If you want to rename a remote computer, you need to specify the name or IP address of the remote computer using the -ComputerName parameter.

In this example, we rename Desktop-01 to Desktop-02. We use the -DomainCredential parameter to specify a user account that has permission to connect to the domain. In this example, is the domain name:

Rename-Computer -ComputerName "Desktop-01" -NewName "Desktop-02" -DomainCredential\administrator

In the following example, we change the name of the computer with an IP Address

Rename-Computer -ComputerName -NewName "Desktop-02" -DomainCredential\administrator -Force -Restart

If the remote computer is not in the domain, use the -LocalCredential parameter to specify a local user account that has permission to rename the computer, as shown in the following example:

Rename-Computer -ComputerName -NewName Desktop1 -LocalCredential\user1

When renaming a remote computer, you may get the following common errors:

  • The RPC server is unavailable.
  • Rename-Computer : Cannot establish the WMI connection to the computer '' with the following error message: Access is denied.

We can solve the first error by enabling the Windows Management Instrumentation from the Windows Firewall on the remote computer. To fix the second error, you need to disable UAC remote restrictions on the target computer.

Click the following link for detailed instructions on how to fix those two errors:

Command Options

The following table describes the parameters of the Rename-Computer Cmdlet.

-NewNameUse this option to specify the new name for the computer. This is the only required parameter.
-RestartUse the -Restart switch to restart the computer.
-ComputerNameUse this option to specify the IP Address or name of the remote computer.
-DomainCredentialSpecifies a domain user account that has permission to rename the computer.
-LocalCredentialWhen renaming a computer that is not on a domain, use this option to specify a local user account that has permission to connect to the remote computer.
-ForceRun the command without asking for user confirmation.
-ConfirmAsks for the confirmation before renaming the computer.
-PassThruReturns the results of the command (shows whether the command was successful or not).
powershell rename computer
Change the Name of a Remote Computer using PowerShell