How to change your domain computer name with Windows PowerShell

Renaming computers or modifying their host names can be tricky, especially when you’re doing it on hundreds of machines at once. If you’re using Windows PowerShell 3.0 or newer, however, you can use the Rename-Computer cmdlet to do this with one command (instead of spending hours going through the usual computer-management interface). Here’s how to change your domain computer name with Windows PowerShell.
Windows PowerShell
Useful for a number of reasons, but most often done because a user has changed their legal name.
Import-Module ActiveDirectory cd ad: cd laborteam64$OU distinguishedname=laborteam64$OU container=dc=laborteam64,dc=com $obj = Get-ADObject -SearchBase $(($Container).distinguishedname) ` -Filter { Name -like * } Set-ADObject $obj.Name New Name
Computer Domain
Changing the name of a computer in Active Directory requires following the instructions for renaming a user account, only using the domain administrator’s credentials. To do this you will need an up-to-date installation of Microsoft Active Directory Management Tools. With this package installed, launch ADSI Edit and right-click on Configuration in the left pane of Windows Explorer. Select Properties from the menu that appears and type (in Object type): Computers. Now expand that node, then expand Domain Controllers and double-click on Computer Name. Select Computer object tab at top of screen, then enter new desired computer name in right pane of screen and click Rename. When prompted, press Enter to confirm old computer name is overwritten with new one before it takes effect. Press OK to complete process.
Step 1: Add the ADDSDeployment module
The first step is adding the ADDSDeployment module for the work you want to do. One way of doing this is by using Import-Module and pointing it at the folder where the module is located: Import-Module .\ADDSDeployment
The next step is loading the ActiveDirectory Active Directory Module, which contains many commands that can be used in AD DS Management: Add-PSSnapin ActiveDirectory.
Step 2: Connect to Domain Controller
It’s important that the first step is to ensure you are using an account that has Domain Admins privileges. However, if the computer isn’t on a domain and is only in a workgroup then this process will not work. Otherwise, type connect-msdsservice and press enter.
Now we need to search for a particular computer, as in our case joly1 which will show us more information about it. Type net view \\joly1 into command prompt and press enter.
Step 3: Rename-Computer commandlet
- If you have never used the Rename-Computer commandlet before, go ahead and type out its name in the prompt: Rename-Computer – WhatIf
- As a result, you will get an output that lists all of the actions it would take on the specified computer including renaming it (i.e., Rename server THNDR), moving files and folders around (Move contents of C:\Windows\Users) as well as creating new files and folders, (Creating C:\Folder1).
- This information is great because it tells you exactly what it is going to do before actually doing anything for real.
Step 4: Reboot
Since we don’t want to keep the same old hostname, that command also includes a line to restart the computer. If you don’t reboot, Windows won’t apply any of those changes until next time it’s powered on and takes a look at the settings again. So if you don’t plan on touching anything for the time being, type in restart (minus quotes) instead of reboot. Alternatively, you can use shutdown -r now instead of restart. Whatever choice you make in this step will start up where it left off when rebooting is finished. After that, you’ll be presented with a logon prompt.
Step 5: Check if it worked
Now that you have done all this, it is time to check if the task was successful. First, open up a new elevated command prompt window and enter: ipconfig /all. Look for two specific values – Primary DNS suffix and NetBIOS domain name. Now compare these two values in the command prompt window with the ones on the Network Connections properties sheet. If they are different then you’re good!