Join a Computer to a Domain

Joins the local computer to a domain and creates the computer's account in Active Directory.

3.9 Star
Add to favorites
Active Directory
E-mail Twitter Digg Facebook
  • add computer account to group
    1 Posts | Last post January 22, 2013
    • Is there a way, in the same script, to join the domain and then add the newly created computer account to an AD group?
  • we have a domain add, how about a domain remove
    2 Posts | Last post December 04, 2012
    • we are shifting loads of PC's from one domain to another and i found this script the easiest to run and fits in nicely with our projected plan, however whilst it adds the computer nicely, it wont allow me to run it on a pc that is already domained (despite the Const DOMAIN_JOIN_IF_JOINED = 32 (or possibly because of it))
      do i need to change that particular line or do i have to run another script first?
      someone help me please
    • While you may have long found the answer, this may help others.  Keep in mind I am no expert and I have not tested my theory yet.
      I belive you may add the constant DOMAIN_JOIN_IF_JOINED to the last paramter as they are cumulative bits.  Therefore the last line would read:
      ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
          strPassword, strDomain & "\" & strUser, NULL, _
      I am referenceing this site where a similar script is posted (please read the comments on this site as well as they have helpful advise to avoid errors):
  • Script error on Windows 2000
    6 Posts | Last post November 26, 2011
    • The script appears to not work on windows 2000 professional when attempting to join to a Windows server 2008 domain, when it is run, I get an error "Object doesn't support this property or method: 'objComputer.JoinDomainOrWorkGroup' "
    • The script worked fine on w2k8 r2 on english....NOt working on German and Spanish. Is there any editing i must do. Please help i really need this script.
    • My works fine...had the wrong settings for those machines..
    • and not work on win 7 (((
    • It does work on windows 7 64 bit.
    • The JoinDomainOrWorkgroup method requires that the domain be at Window Server 2003 functional level or above, and the client must be Windows XP or above. A log is created at c:\Windows\debug\NetSetup.log. As already noted, the DN of the parent OU, where the computer object will be created, can be specified as the fourth parameter of the method (in place of Null in this example). You can also modify the script to prompt for the username and password.
  • Passwords in scripts
    3 Posts | Last post November 15, 2011
    • For anyone reading this, it is not best practice or even remotely recommended to store passwords in plain-text.  This script is only giving an example of what is possible via scripting.
    • Here is an example of how to join a computer to the domain using Powershell where you do not have to store the password in plain-text.
    • Good note. This should be added to the description.
  • Nice Script but it seems... khm... useless...
    2 Posts | Last post September 13, 2011
    • Script is small and nice but it repeats standart feature - Computer's account creates in standart OU.
      Is it possible to choose OU where computer's account will be created?
      Netdom can do it but console is too hard for my specialist ... Hm...
      Who knows how to join computer to preselected OU in microsoft way - by 2 or 3 clicks in GUI?
    • Vitaliy, the method that he uses does allow you to specify the OU.  It should be the 4th overload in the method, which is the last line of code.  
      ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _ 
          strPassword, strUserName, "OU=MyComputers,DC=domain,DC=com")
  • explanation on script code
    1 Posts | Last post March 07, 2010
    • I wanted to understand step by step, how code of script 'join a computer to a domain' works?