How to Rename Computer and Join to Domain With PowerShell
PowerShell has the Add-Computer
cmdlet that adds the local or remote computer to a domain or workgroup. This article will tackle how to rename the computer and join a domain in one step with PowerShell.
Use -NewName
Parameter to Rename Computer and Join to Domain With PowerShell
The following command adds the local computer to the domain delftstack
and then restarts the computer. Run the PowerShell as an administrator; otherwise, you will get the access denied errors.
Command:
Add-Computer -DomainName delftstack -Restart
It’ll prompt you to enter the credentials of a domain user account who has permission to join computers to the new domain. When the credentials match, the computer will restart and join the domain.
Output:
The Add-Computer
does not return any outputs. If you want to get outputs, use the command with the -Verbose
and -PassThru
parameters.
You can use the -NewName
parameter to rename the computer name and join the domain. It sets a new name for the computer in the new domain.
This command adds the computer DelftPC
to the domain delftstack
and changes the computer name to DelftPC01
. The -Credential
parameter specifies a user account to join the computer to the domain.
Command:
Add-Computer -ComputerName DelftPC -DomainName delftstack -NewName DelftPC01 -Credential delftstack\admin -Restart
Output:
Another cmdlet you can use to rename the local or remote computer is Rename-Computer
. The following command renames the local computer to DelftPC02
and restarts the computer to make the change effective.
Command:
Rename-Computer -NewName DelftPC02 -DomainCredential delftstack\admin -Restart
Output:
You can also move computers from one domain to another using the Add-Computer
.