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.
01Command
$ Add-Computer -DomainName "corp.example.com" -Credential CORP\admin -Restart02What 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
04Undo
$ Add-Computer -WorkgroupName "WORKGROUP" -Restart05Sources
- Add-ComputerEvidence: 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
Search inside text files and logs with regex, returning file, line number and match.
Create or update a .zip from any files or folder contents straight from PowerShell.
A built-in PowerShell one-liner that answers 'is port 5432/3389/443 actually open through this network?' — no telnet client needed.