How to Join Computer to Domain using PowerShell. Active Directory (AD) is a technology that thousands of businesses rely on daily. We must join computers to an AD domain to take advantage of AD. However, we need to realize there are many ways to do that, some better than others. This article teaches us how to add a machine to a domain using the Windows Graphical User Interface (GUI) command line with PowerShell.
How to Join Computer to Domain using PowerShell
If we want to complete all of the steps in this tutorial, we must have the following items:
Joining a Computer to a Domain via the GUI
Remember, the GUI is one of the most common methods for adding a computer to an AD domain. This approach is good when we add a single or a few computers simultaneously. However, this method is unsuitable for adding multiple computers simultaneously.
Suppose our computer cannot contact the domain name we entered immediately. In that case, it will throw the below error:
If the computer cannot reach a domain controller, ensure the computer’s DNS server points to a domain controller.
9. When we click Close, Windows will ask us to restart. To restart the computer immediately, click Restart now.
Improve your Active Directory Security & Azure AD
Try us out for Free, Access to all features. – 200+ AD Report templates Available. Easily customise your own AD reports.
Joining a Local Computer to a Domain via the Settings app
5. Enter the domain name and click Next on the next page.
7. On the next page, select the account type that will use this machine.
- If we select Administrator, we will add the user we used to add this machine to the domain to the local administrators’ group on the device.
- Selecting a standard user will not add the user to the local administrator’s group. We can also skip it and continue to the next page.
Joining a Local Computer to a Domain via Netdom
Netdom is a command-line tool that allows us to manage trust relationships between computers. It can join a computer to a domain and perform other tasks, such as resetting machine account passwords and creating trust between domains. Follow the instructions below to join the computer using netdom commands:
1. Start cmd.exe as administrator.
2. Use netdom join with the following parameters.
netdom.exe join %COMPUTERNAME% /domain:DOMAIN /UserD:DOMAIN\USERNAME /PasswordD:PASSWORD
Joining a Local Computer to a Domain via PowerShell
If we have many computers to add to a domain, an onboarding automation process, or prefer the command line, we can use PowerShell. Follow the instructions below to join multiple computers to the domain using PowerShell:
1. Open Windows PowerShell, making sure to run it as administrator.
2. Run the Add-Computer cmdlet from the PowerShell console. This cmdlet does the same thing as adding a computer to a domain through the GUI. First, use the DomainName parameter to specify the domain name to which we will add the computer. Then, optionally set the Restart parameter to restart the computer when the process is complete.
Add-Computer -DomainName DOMAINNAME -Restart
Join a Local Computer to a Domain via WMI
To ensure that this article covers all possible methods for adding a computer to a domain, let’s move on to a less known way of using Windows Management Instrumentation (WMI). WMI is a common component of Windows that contains a wealth of information about a computer and can perform actions on it.
1. Start Windows PowerShell as an administrator.
2. Run the command below:
(Get-WMIObject -NameSpace "Root\Cimv2" -Class "Win32_ComputerSystem").JoinDomainOrWorkgroup("DOMAIN.COM","PASSWORD","DOMAIN\USER",$null,3)
3. When completed, restart the computer.
Adding Computers Remotely to a Domain
To join remote computers to the domain remotely, invoke the Add-Computer PowerShell cmdlet. But this time, use the ComputerName parameter. To run the Add-Computer cmdlet remotely, we must ensure that we enable PSRemoting on all remote computers.
1. Open PowerShell as administrator on our workstation
2. Execute the following command. We may refer to the command below:
Add-Computer -ComputerName COMPUTERNAME -LocalCredential DOMAIN\LOCAL -DomainName DOMAIN -Credential DOMAIN\ADMIN -Restart
By default, the Add-Computer cmdlet will not restart the remote computer if a logged-in user is in session. To override this, specify the Force switch parameter to restart the remote computer constantly.
Thank you for reading this article blog about How to Join Computer to Domain using PowerShell. We shall conclude.
How to Join Computer to Domain using PowerShell Conclusion
In conclusion, using PowerShell to join a computer to a domain is a quick and efficient way to add a new device to your network. By following the steps outlined in this article, you can quickly join a computer to a domain and begin using it as a fully fledged member of your organization. Whether you are a network administrator or simply looking to add a new device to your home network, PowerShell offers a powerful and convenient way to get the job done.
Try InfraSOS for FREE
Invite your team and explore InfraSOS features for free