Renaming computers suck! Sure, there are worse things in life like famine, natural disasters, etc. Regardless though, the process is way more tedious than it should be. You have to remote in and kick off any logged on user. Even if you use Concurrent RDP, it is still a time consuming process. At least it was until PowerShell came along.

PowerShell 3.0 introduced the Rename-Computer cmdlet and made this task so much easier! Just to show you how easy, we are going to tackle three common tasks with this one cmdlet. We will:

Remotely rename a single online computer

Remotely rename multiple online computers

Schedule renames for multiple computers (offline and online)

How to Remotely Rename a Computer with PowerShell

For most of this article, we will be using PowerShell ISE for our scripts. In the script pane (top console), type rename-computer and press F1. This is bring up the help file for the rename-computer cmdlet.*

You will notice that the only required parameter is -NewName. If you wanted to rename your local computer, you could type Rename-Computer NEWCOMPUTERNAME

Renaming a computer remotely with PowerShell is just as easy; all you’ll need is the -ComputerName parameter. Here is an example that renames a computer named PC1 to PC-1.

Rename-Computer -NewName PC-1 -ComputerName PC1

How to Remotely Rename Multiple Computers with PowerShell

In this example, we are going to use the Quest AD PowerShell cmdlets to export a list of computers to a CSV file. We are then going to edit the CSV file to contain our new computer names.

Schedule Renames for Multiple Computers

If you are renaming a large amount of computers (or working with machines that aren’t always connected), you will likely find the options above lacking. With a few modifications, you can have your computers rename themselves. With all of that spare time you now have, you can keep reading DeployHappiness. Doesn’t that sound like a win-win! Good, here is our script:

Like our example above, this script relies on a CSV file containing our current and new computer names. The only real difference from above is the If statement. In PowerShell, $?stores the exit value of the previous command. So by saying if ($? -eq $True), we are saying “if the computer rename was successful.

If the rename was successful, we read the content of the CSV file and remove the newly renamed computer from the list. After running this script, only computers that weren’t successfully renamed will be left. By setting this script to run as a scheduled task, you can automate a large rename process with little effort! Of course, you will still want to ensure that you don’t accidentally create duplicate computer names.

If you are having issues you may want to use -DomainCredential Get-Credential. You can also create a variable for you credentials which may me helpful so it does not ask you every time you run the script.