Skip to main content
Jorge Bernhardt Jorge Bernhardt
  1. Posts/

How to add Computer to a Domain using PowerShell

·285 words·2 mins· 100 views · 5 likes ·
Add-Computer Microsoft Microsoft Windows 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.

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 the PowerShell console as administrator, and then type:

Add-Computer `
    -NewName <String> `
    -DomainName <domainName> `
    -DomainCredential <domainAdminUser> `

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: -NewName Specify a new name for the computer in the new domain. This parameter is valid only when one computer is being added or moved. -Server Specifies the name of a domain controller that adds the computer to the domain. -OUPath 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” -Options Specifies advanced options for the Add-Computer join operation. This parameter I will explain this in a forthcoming post.

If you want to know more about the Add-Computer cmdlet, check out this link.