Link to home
Start Free TrialLog in
Avatar of cyrax
cyraxFlag for Australia

asked on

Script to add computer to Windows domain

Hello,

Need a script that adds a Windows XP computer from one domain to another domain.
Can anyone help?

THank you!
Avatar of arichterwork
arichterwork

There are a couple of other threads around on EE explaining how to do this, but quoting iress from https://www.experts-exchange.com/questions/21218248/Script-to-Join-a-Domain.html states to run this command (if you do not have netdom, please "Install Windows XP Support Tools from the Support\Tools folder on the Windows XP Professional CD-ROM." [from http://support.microsoft.com/default.aspx?scid=kb;en-us;298593&sd=tech]):

netdom join %computername% /Domain:<Domainname>/UserD:<Username> /PasswordD:<Password> /OU:"OU=<Containername>,DC=Test,DC=com,DC=au" /REBoot:20
Avatar of cyrax

ASKER

Is there a way of performing the task without using the Netdom command? Would prefer a script if possible.

Thanks.
You can place a call to that in a script shell object, but I have not seen anything to do it without using the netdom join command.
My apologies, try this: http://cwashington.netreach.net/depo/view.asp?Index=1144&ScriptType=vbscript

Scroll down the page, and look for the routine "Sub Join2Domain".  It states it only works on WinXP, but that is what you were looking for.
Avatar of cyrax

ASKER

Since the computer is already on a domain, and I need to join it to another domain, does it need to be disjoined from the existing domain and added to a workgroup first before joining it to the new domain?
The heart of the Join2Domain routine is the method "JoinDomainOrWorkgroup" (in detail on MSDN http://msdn2.microsoft.com/en-us/library/aa392154.aspx).  It says you must remove from the domain if adding to a workgroup, but you can force it to move from one domain to another through the last parameter.
In the code sample on netreach.net (in previous post), you would modify:
-------------
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
strPassword, _
strDomain & "\" & strUser, _
strOU, _
JOIN_DOMAIN + ACCT_CREATE)
-------------
to read:
-------------
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
strPassword, _
strDomain & "\" & strUser, _
strOU, _
DOMAIN_JOIN_IF_JOINED)
-------------
The variable "DOMAIN_JOIN_IF_JOINED" is specified a few lines above (in the article) as having value 32.  This can be combined with other options (that the author specified in those constants) by adding them, similar to the author's use of "JOIN_DOMAIN + ACCT_CREATE".

Alternately, there is a method called "UnjoinDomainOrWorkgroup" (in detail on MSDN http://msdn2.microsoft.com/en-us/library/aa393942.aspx), which you could perform prior to joining the new domain.

Hope this helps.
Avatar of cyrax

ASKER

Thanks. Still trying the NETDOM solution, but can't seem to get it to work...
Is it necessary to specify the OU in the command string?

Which NETDOM should be used - one from a Windows XP CD or a Windows Server 2003 CD? I noticed that they are different.
ASKER CERTIFIED SOLUTION
Avatar of arichterwork
arichterwork

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial