Running a PowerShell command to join a domain adds the computer to an Active Directory domain, enabling centralized management, user authentication, and policy enforcement. You must have domain administrator credentials and local admin rights on the target machine. This process is essential for enterprise environments where devices need to integrate with on-premises or cloud-managed directories like Azure AD (via hybrid join or domain join first).

What You'll Need

  • A Windows device running Windows 10 Pro, Enterprise, or Education (Home editions cannot join domains)
  • Domain administrator credentials (e.g., domain\adminuser)
  • Local administrator credentials on the target machine
  • Network connectivity to the domain controller (DNS must resolve the domain name)
  • PowerShell running with administrative privileges (Run as Administrator)
  • The fully qualified domain name (FQDN) of the domain (e.g., contoso.com)

Step-by-Step

  1. Open PowerShell as an administrator: Press Win+S, type "powershell", right-click "Windows PowerShell", and select "Run as administrator". Confirm any User Account Control prompt.
  2. Verify your current workgroup by running: Get-ComputerInfo | Select-Object -Property CsName, Workgroup. Note the output for reference.
  3. Prepare the domain join credentials. Store them securely in a variable using: $cred = Get-Credential. In the pop-up window, enter the domain administrator's username (e.g., contoso\admin) and password, then click OK.
  4. Run the domain join command: Add-Computer -DomainName contoso.com -Credential $cred -Restart -Force. Replace "contoso.com" with your domain's FQDN. The -Restart parameter automatically reboots the machine after joining, and -Force suppresses confirmation prompts.
  5. Monitor the PowerShell window. You should see output indicating the computer is being joined to the domain, followed by a restart prompt. After reboot, the machine will boot into the domain-joined state.
  6. Post-restart, log in using a domain account (e.g., contoso\username) to confirm successful domain membership. You can verify via whoami /fqdn or systeminfo | findstr /B /C:"Domain".

Common Mistakes

  • Using an incorrect domain name—ensure it matches the FQDN in Active Directory (e.g., use "corp.local", not "corp")
  • Running PowerShell without elevation—non-admin sessions will fail with "Access Denied"
  • Typing the domain admin username without the domain prefix (e.g., "admin" instead of "corp\admin")
  • Forgetting to include -Force when scripting—this causes the command to pause and wait for user input, breaking unattended deployments
  • Attempting to join from a machine whose DNS settings point to a non-domain DNS server (e.g., public DNS like 8.8.8.8), which prevents domain controller discovery
  • Using a local user account with admin rights instead of a domain admin account for the -Credential parameter

Tips

  • For unattended scripts, pre-store credentials via ConvertTo-SecureString and NetworkCredential only in secure environments—never hardcode plaintext passwords
  • Test DNS resolution first with nslookup contoso.com to verify the domain controller is reachable
  • Use -OUPath "OU=Servers,DC=contoso,DC=com" to specify an organizational unit for the computer object, avoiding the default "Computers" container
  • Run Test-Connection domaincontroller.contoso.com -Count 2 to confirm basic connectivity before attempting the join
  • After joining, run gpupdate /force to immediately apply Group Policy settings
  • For Azure AD-joined devices, domain join via PowerShell only works for hybrid scenarios; pure Azure AD devices require different methods (e.g., Autopilot)

Troubleshooting

If the command fails, start with these checks:

  • "The specified domain either does not exist or could not be contacted": Verify DNS settings on the client. Run ipconfig /all and confirm the primary DNS suffix matches the target domain and the DNS server points to a domain controller or forwarder. Flush DNS with ipconfig /flushdns and retry.
  • "Access is denied": Confirm the credential provided has domain admin rights. Test with Test-NetConnection -ComputerName domaincontroller.contoso.com -Port 389 to validate LDAP connectivity. Also ensure the local machine's time is synchronized within 5 minutes of the domain controller (use w32tm /resync).
  • Command hangs or prompts for input despite -Force: Check for Group Policy restrictions blocking unattended joins. Try running Add-Computer -DomainName contoso.com -Credential $cred -Verbose to see detailed progress and identify where it stalls.
  • Machine reboots but does not join the domain: Check Event Viewer (Applications and Services Logs > Microsoft > Windows > ComputerBrowser > Operational) for join errors. Also verify the domain controller has sufficient disk space and the NTDS service is running.
  • Post-reboot login fails with "The trust relationship failed": This often indicates a password mismatch between the machine account and domain controller. Reset the computer account in Active Directory Users and Computers, then re-run the join command.

Frequently Asked Questions

Can I join a domain without rebooting?

Yes—omit the -Restart parameter. After running Add-Computer, manually restart the machine later. However, the computer will not function as a domain member until rebooted.

Does this work on Windows 11 Home?

No. Windows 11 Home does not support domain joining. You must upgrade to Windows 11 Pro or Enterprise first.

Can I use a Microsoft account instead of a domain account?

No. Microsoft accounts (e.g., user@outlook.com) are for consumer sign-ins. Domain joins require an on-premises Active Directory or Azure AD account with appropriate privileges.

Is it safe to store credentials in a PowerShell variable?

Only temporarily. The $cred variable holds credentials in memory for the current session and is discarded after PowerShell closes. Avoid piping credentials to files or logs.

What if my domain uses a different port (not 389)?

The Add-Computer cmdlet uses standard LDAP ports (389 for unencrypted, 636 for LDAPS). If your environment requires a custom port, you cannot specify it directly. Instead, ensure DNS SRV records are correctly configured for automatic discovery.

Can I join multiple computers remotely using this method?

Yes—use PowerShell remoting (Invoke-Command or Invoke-Command -ComputerName) to run the Add-Computer command on remote machines. Ensure WinRM is enabled and the remote machines are reachable over the network.