How to Easily Rename a Windows Computer Using PowerShell?

Recently I needed to change the name of one of our company’s laptops from “JohnS-Surface” to “SalesDemo-Chicago”. Rather than manually renaming it through the Windows GUI, I used a simple PowerShell command called Rename-Computer to get the job done in seconds. In this tutorial, I will explain how you can quickly rename a Windows computer using PowerShell.

PowerShell provides an efficient way for IT admins and power users to rename Windows machines either locally or remotely. This is handy when you need to update a PC name to follow a new naming convention, repurpose a computer for a new user or location, or simply make the name more descriptive.

Change a Windows Computer Using PowerShell Using Rename-Computer

The PowerShell cmdlet to change a computer’s name is called Rename-Computer. It allows you to specify the new name you want to assign to the local PC or a remote computer.

Here is the basic syntax:

Rename-Computer -NewName "NewComputerName"

For example, let’s say you want to rename a laptop named “JohnS-Surface” to “SalesDemo-Chicago”. Simply open PowerShell as an administrator and run:

Rename-Computer -NewName "SalesDemo-Chicago"

PowerShell will display a prompt asking you to confirm the name change and warning you that you’ll need to restart the computer for it to take effect. Type “Y” for yes and press Enter. The computer will be renamed after it reboots.

Check out Change Wallpaper with PowerShell

Rename a Remote Computer using PowerShell

One of the useful features of PowerShell is the ability to manage computers remotely. With the right permissions, you can connect to a remote machine and rename it without being physically present.

To do this, use the -ComputerName parameter to specify the name or IP address of the remote computer:

Rename-Computer -ComputerName "OldName" -NewName "NewName" 

For instance, to rename a remote server from “FileServer01” to “USFileSrv-Prod”:

Rename-Computer -ComputerName "FileServer01" -NewName "USFileSrv-Prod"

You’ll be prompted to provide credentials that have administrator rights on the remote machine. Enter valid admin credentials, and the remote computer will be renamed.

Check out Disable Local User Computer Accounts Using PowerShell

Rename Multiple Computers using PowerShell

What if you need to rename a whole bunch of computers to match an updated naming scheme? Rather than manually running Rename-Computer on each one, you can automate the process with PowerShell.

For example, let’s say you have a text file called computers.txt that contains a list of existing computer names, one per line:

DesktopPC1
LaptopPC2 
DesktopPC3

And you want to prefix each name with “US-” to identify them as machines located in the United States. Here’s a PowerShell script that will loop through that list, generate the new names, and rename each computer:

$computers = Get-Content "C:\computers.txt"

foreach ($computer in $computers) {
  $newName = "US-" + $computer
  Rename-Computer -ComputerName $computer -NewName $newName
}

This will rename “DesktopPC1” to “US-DesktopPC1”, “LaptopPC2” to “US-LaptopPC2”, and so on. Bulk renaming PCs like this with PowerShell can save a ton of time.

Rename a Windows Computer Using PowerShell

Conclusion

In this tutorial, I explained how to use the Rename-Computer cmdlet in PowerShell to change a Windows computer’s name. Also, I explained how to rename a remote server using PowerShell. Finally, I explained how to rename multiple computers using PowerShell.

You may also like:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.