How to add Computer to a Domain using PowerShell
Suppose you want to add a computer to a domain using the command line, either when no GUI (Server Core) or just when configuring multiple computers in a script. This post can be interesting for you. The Add-Computer cmdlet adds the local or remote computers to a domain or workgroup or moves them from one domain to another.
Add-Computer `
-ComputerName <String[]> `
-NewName <String> `
-DomainName <String> `
-Credential <PSCredential> `
-Restart
The instructions in this post assume that DNS resolution is working correctly, i.e., you can resolve the domain name of the Active Directory domain you want to join and that you have connectivity to a domain controller. The Add-Computer cmdlet required the following parameters: DomainName or workgroup name and DomainCredential or Credential for Workgroup. Run the PowerShell console as administrator, and then type:
Add-Computer `
-NewName <String> `
-DomainName <domainName> `
-DomainCredential <domainAdminUser> `
-restart
In this case, I want to change the computer’s name in the same action.
If you want to know more about the Add-Computer cmdlet, check out this link.