Join Domain using Powershell

To join a computer to the domain, it requires domain admins privileges.

  • Join to a Domain
Add-Computer -DomainName "domain.com" -Restart
  • Join to a Domain Controller with Verbose mode
Add-Computer -DomainName Domain01 -Server Domain01\DC01 -PassThru -Verbose
  • Join and move to specific OU
Add-Computer -DomainName Domain02 -OUPath "OU=testOU,DC=domain, DC=Domain,DC=com"
  • Join domain Using and put credential.
Add-Computer -ComputerName Server01 -LocalCredential Server01\Admin01 -DomainName Domain02 -Credential Domain02\Admin02 -Restart -Force
  • Join domain Using and put credential and move the computer to a new domain
Add-Computer -ComputerName Server01, Server02, localhost -DomainName Domain02 -LocalCredential Domain01\User01 -UnjoinDomainCredential Domain01\Admin01 -Credential Domain02\Admin01 -Restart

Unjoin from domain in Powershell

Remove-Computer -UnjoinDomaincredential Domain01\Admin01 -PassThru -Verbose -Restart
  • Unjoin several computers from the domain.
Remove-Computer -ComputerName "Server01", "Server02" -UnjoinDomainCredential Domain01\Admin01 -WorkgroupName "Local" -Restart -Force
  • Unjoin listed computers from the domain.
Remove-Computer -ComputerName (Get-Content OldServers.txt) -LocalCredential Domain01\Admin01 -UnJoinDomainCredential Domain01\Admin01 -WorkgroupName "Workgaroup" -Force -Restart