Last Update: Sep 04, 2024 | Published: May 15, 2014
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).
Once you’ve established correct DNS resolution for the domain name, start a PowerShell prompt with local administrative privileges.
The PC should now restart and be joined to the domain once it has restarted.
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.
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.