Learn What IT Pros Need to Know About Windows 11 - August 24th at 1 PM ET! Learn What IT Pros Need to Know About Windows 11 - August 24th at 1 PM ET!

How to Add Computers to a Domain Using PowerShell

Sometimes it can useful to add a computer to a domain using the command line, such as when no GUI is available (as is the case with Server Core), or just to expedite the process when configuring multiple computers. In this easy Ask the Admin, I’ll show you how to add one or more Windows 8.1 and Windows Server 2012 R2 PCs to a domain using PowerShell.

The instructions in this article 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 (DC).

Performing a Domain Join Using PowerShell

Once you’ve established correct DNS resolution for the domain name, start a PowerShell prompt with local administrative privileges.

  • Press the Windows key to switch to the Start menu, type PowerShell and press CTRL+SHIFT+ENTER. If prompted, enter a local administrator username and password, or give consent to run PowerShell.
  • In the PowerShell prompt, type add-computer –domainname ad.contoso.com -Credential AD\adminuser -restart –force and press Enter. Enter a password for the domain administrator account when prompted.

The PC should now restart and be joined to the domain once it has restarted.

Sponsored Content

Read the Best Personal and Business Tech without Ads

Staying updated on what is happening in the technology sector is important to your career and your personal life but ads can make reading news, distracting. With Thurrott Premium, you can enjoy the best coverage in tech without the annoying ads.

Add a computer to a domain using PowerShell
Add a computer to a domain using PowerShell.

Join Multiple PCs to a Domain

You can add more than one computer to the domain, either by using names from a text file or listing them in the command line as a comma-delimited list. You can use the –computername parameter even if PowerShell Remoting isn’t enabled on the computers listed in the command line.

  • In a PowerShell command prompt, type add-computer -computername srvcore01, srvcore02 -domainname ad.contoso.com –credential AD\adminuser -restart –force and press Enter.
  • Type a password for the domain administrator account when prompted.

The command above adds srvcore01 and srvcore02 to ad.contoso.com domain. The account used to run the PowerShell prompt would need permission to connect and join both servers to the domain. You could also specify a list of servers in a text file (servers.txt) as follows:

add-computer -computername (get-content servers.txt) -domainname ad.contoso.com –credential AD\adminuser -restart –force

In the above command, servers.txt would need to be located in the PowerShell working directory.

Related Topics:


Don't have a login but want to join the conversation? Sign up for a Petri Account

Comments (2)

2 responses to “How to Add Computers to a Domain Using PowerShell”

  1. Florian

    Hi, Thanks for this article. However, in my opinion, in the case of you want add multiple computers, you must use also the option "LocalCredential". With this option, you authenticate on the remote PC. Florian, www.it-connect.fr
  2. Russell Smith

    Hi Florian, I'm glad you found this article useful. I think it depends on the situation. If you don't specify the -LocalCredential option, then the current user authenticates to the listed PCs. Naturally, that might cause an authentication failure, in which case the -LocalCredential option would be necessary.

Leave a Reply

IT consultant, Contributing Editor @PetriFeed, and trainer @Pluralsight. All about Microsoft, Office 365, Azure, and Windows Server.

Register for Advanced Microsoft 365 Day!

GET-IT: Advanced Microsoft 365 1-Day Virtual Conference - Live August 24th!

Join us on Tuesday, August 24th and hear from Microsoft MVPs and industry experts about how to take advantage of Microsoft 365 at a technical level and dive deep into the features and functionality that will make your environment more secure and compliant.


Sponsored By