Join a Domain or Workgroup with Add-Computer

Attach a Windows PC to an Active Directory domain (or pull it back to a workgroup) with one PowerShell command.

WindowsaccountspowershelldomainMedium risk
Run Add-Computer -DomainName "yourdomain.local" -Credential DOMAIN\admin -Restart in an elevated PowerShell to join the domain and reboot.

01Command

Command
$ Add-Computer -DomainName "corp.example.com" -Credential CORP\admin -Restart

02What it does

Joining a domain wires the machine into company logins, group policies, and shared resources, and Add-Computer does the same job as the System Properties GUI with scriptable flags. Provide an account that has permission to create computer objects; without -Credential it prompts for one. To leave a domain, point the same cmdlet at -WorkgroupName instead. The join only completes after the mandatory restart, so keep -Restart or schedule the reboot yourself.

03Risk

RiskMedium risk
RequirementsPowerShell as Administrator; domain credentials with computer-join rights
!Warning: Wrong OU placement or missing computer-object permissions cause cryptic "access denied" errors — confirm with your IT department which OU new machines go into.

04Undo

Undo
$ Add-Computer -WorkgroupName "WORKGROUP" -Restart

05Sources

  • Add-Computer
    Microsoft Learn · vendor-doc · 2026-09-17
    Evidence: Documents Add-Computer for joining a domain (-DomainName, -Credential) or a workgroup (-WorkgroupName), with -Restart to apply immediately.

Last verified: 2026-09-18 · Category: System & Settings

06Related solutions