How to join a computer to domain from command line

We can join a computer to a domain from system properties window. Some times we may need to do this from command line or from a batch file without any user interaction. We can use the tool Netdom.exe in such scenarios.

Below is the command we need to run for joining the machine to a domain.

netdom.exe join %computername% /domain:DomainName /UserD:DomainName\UserName /PasswordD:Password

Here Username and Password should be of a  the domain specified in /domain switch. The user should have privileges to join a computer to the domain.

How to remove a computer from a domain using netdom?

You can run the below command to remove a machine from the domain.

netdom.exe remove %computername% /domain:Domainname /UserD:DomainName\UserName /PasswordD:Password

Download Netdom.exe