How to Add Computers to a Domain Using PowerShell

Russell Smith profile picture
Russell Smith Editorial Director

Russell Smith, the Editorial Director at Petri IT Knowledgebase, has over two decades of hands-on experience in IT, in both small business settings and government IT infrastructure projects. Russell started writing for Windows IT Pro Magazine in t...

Sometimes it can be 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 ADadminuser -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.

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 ADadminuser -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 ADadminuser -restart –force

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

FAQs
How do I troubleshoot errors when joining a domain using PowerShell?

Common issues include “Access Denied” or “The network path was not found.” To troubleshoot:

  • Ensure PowerShell is running as administrator.
  • Confirm DNS is correctly configured to resolve the domain.
  • Verify network connectivity to a domain controller.
  • Double-check your credentials. You can also run Test-ComputerSecureChannel -Verbose to test domain trust status.

Can I join a computer to a domain remotely using PowerShell?

Yes. Use the -ComputerName parameter with the Add-Computer cmdlet. Make sure:

  • WinRM (Windows Remote Management) is enabled on the target machine.
  • You have administrative credentials.
  • The firewall allows remote PowerShell commands.

What are the prerequisites for joining a domain from a workgroup using PowerShell?

To join a domain from a non-domain-joined (workgroup) machine:

  • You must be logged in as a local administrator.
  • The machine must have network access to the domain controller.
  • DNS should point to a domain controller.
  • PowerShell 3.0 or later must be installed.
  • You’ll need valid domain credentials.

How can I confirm that a computer has successfully joined the domain?

After running Add-Computer, you can verify domain membership by:

  • Running Get-WmiObject Win32_ComputerSystem | Select-Object Domain
  • Using Test-ComputerSecureChannel
  • Checking Get-ComputerInfo | Select-Object CsDomain

Can I schedule domain join operations with PowerShell?

Yes. You can:

  • Write a script using Add-Computer
  • Secure credentials using Get-Credential and Export-Clixml

Schedule the script with Task Scheduler or a PowerShell Scheduled Job This is useful for joining multiple computers during off-hours or deployments.