Suppose you want to add a computer to a domain using the command line, either as 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.
To add a computer to a domain with PowerShell, use the Add-Computer cmdlet with the following syntax:
Add-Computer -ComputerName <String> `
-NewName <String> `
-DomainName <String> `
-Credential <PSCredential> `
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 PowerShell console as administrator, and then type:
Add-Computer –DomaiName <domain.com> -DomainCredential <domainadminuser> -restart
In this case, I want to change the computer’s name in the same action.
The Add-Computer cmdlet accepts some very useful optional parameters:
Specify a new name for the computer in the new domain. This parameter is valid only when one computer is being added or moved.
Specifies the name of a domain controller that adds the computer to the domain.
Specifies an organizational unit (OU) for the domain account. Enter the full distinguished name of the OU in quotation marks.
“OU=W2k12 R2 Servers,OU=Servers,DC=Domain,DC=local”
Specifies advanced options for the Add-Computer join operation. This parameter I will explain in a forthcoming post.
If you want to know more about the Add-Computer cmdlet, check out this link: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/add-computer?view=powershell-5.1