How To Add Computers To A Domain Using PowerShell
Maybe your like
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.
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.
FAQsHow 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.
Tag » Active Directory Add Computer To Domain Powershell
-
Add-Computer (Microsoft.PowerShell.Management)
-
Join Computer To Domain Using PowerShell - Active Directory Pro
-
How To Add A Computer To A Domain (GUI And PowerShell)
-
How To Manage Computers In Active Directory Using PowerShell
-
Script To Add Windows Devices To Active Directory Domain - Hexnode
-
How To Add Computer To A Domain Using PowerShell
-
Add A Computer To An Active Directory Domain With PowerShell
-
Active Directory: How To Join A Computer To The Domain Using GUI Or ...
-
Adding Active Directory Users, Groups And Computers With PowerShell
-
How To Join Computer To The AD Domain Using PowerShell?
-
Join Computer To Domain Using Windows Powershell! - YouTube
-
Active Directory Queries With PowerShell - ScriptRunner
-
Create Computer Objects In Active Directory Using PowerShell
-
Active Directory PowerShell Script To Add Computers To AD Group