Solved

join a computer to the domain with a script

Posted on 2009-06-28
18
369 Views
Last Modified: 2012-05-07
I wonder if someone has used a script to join a computer to the domain.
I used a script in an environment and worked fine, the same script tried it in a different environment and it never worked.
So if someone has a similar script that can join a computer to the domain. please post it here.

Thanks.
0
Comment
Question by:jskfan
  • 12
  • 4
  • 2
18 Comments
 
LVL 23

Expert Comment

by:ComputerTechie
ID: 24733245
0
 

Author Comment

by:jskfan
ID: 24735310
My environment is windows 2003 servers/windowsXP/Vista.
0
 

Author Comment

by:jskfan
ID: 24773174
any updates????
0
 
LVL 23

Expert Comment

by:ComputerTechie
ID: 24773326
0
 

Author Comment

by:jskfan
ID: 24784531
I will try it later.......it looks like I have the same script but it's not working...
0
 

Author Comment

by:jskfan
ID: 24785829
where do you run this script from?
0
 
LVL 23

Accepted Solution

by:
ComputerTechie earned 500 total points
ID: 24785995
you can run it from server. make sure to change as directed in the post and in lines 37-39

CT
0
 

Author Comment

by:jskfan
ID: 24802754
I did run it from the server that I needed to join to the domain. it prompt me for computer name, I typed the computer name and it said computer renamed successfully, then it gave me a message error 0 exiting script, then it rebooted the computer. I logged in and the computer is still in workgroup, it didn't get joined to the domain.
0
 

Author Comment

by:jskfan
ID: 24802773
this is exactely the error I got

<<<Join Domain failed. error=0 Exiting script>>
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:jskfan
ID: 24804226
This script below does the right job, but only when I run it locally in the machine I want to join to the domain.
I tried to run it remotelt using PSexec but it doesn't run the script::
PSexec \\remotecomputername cscript.exe C:\file.vbs
it says something about the script exited with error code: 0
if I use PSexec \\remotecomputername wscript.exe C:\file.vbs
the scripts hangs on forever

Here is the script that runs good when locally executed.




wscript.sleep 60
Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
Const ACCT_DELETE = 4
Const WIN9X_UPGRADE = 16
Const DOMAIN_JOIN_IF_JOINED = 32
Const JOIN_UNSECURE = 64
Const MACHINE_PASSWORD_PASSED = 128
Const DEFERRED_SPN_SET = 256
Const INSTALL_INVOCATION = 262144
 
strDomain = "mydomain.com"
strPassword = "domainpassword"
strUser = "Administrator"
 
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
wscript.echo strcomputer
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
    strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
        strComputer & "'")
 
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
    strPassword, strDomain & "\" & strUser, NULL, _
        JOIN_DOMAIN + ACCT_CREATE)
Dim oShell
 
Set oShell = CreateObject("Wscript.Shell")
sReturn = oShell.Run("%comspec% /c shutdown -r -t 0 -f")
0
 
LVL 23

Expert Comment

by:ComputerTechie
ID: 24804328
canyou put the script on a network share and run it

here is another post from another person asking the same thisng.

http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_23830424.html

CT
0
 

Author Comment

by:jskfan
ID: 24804410
how do you run it from the share using psexec?
0
 

Author Comment

by:jskfan
ID: 24804436
I even create a GPO logon script and it didn't work.
0
 

Author Comment

by:jskfan
ID: 24804572
Wow.......PSexec is working fine now
PSexec \\RemoteComputerName cscript -i  -d cscript.exe C:\file.vbs

file.vbd is the script I pasted above in the thread.

it joined the computer to the domain and rebooted it.

0
 

Author Comment

by:jskfan
ID: 24804622
I wonder what the switches -i and -d  did to help.
I looked the psexec help and could not understand it
0
 
LVL 47

Expert Comment

by:Donald Stewart
ID: 24804675
have you tried the script here?
 
http://techtasks.com/code/viewbookcode/1642 
0
 
LVL 47

Expert Comment

by:Donald Stewart
ID: 24804683
0
 

Author Comment

by:jskfan
ID: 24805310
dstewartjr:

why world I try it.the one I posted worked.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How can i reset all images size to default in a word file 6 58
Running a powershell task to call exe while logged off 8 62
Convert MSI to MSM 1 49
React or Angular? 6 51
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
When you upgrade from Windows 8 to 8.1 or to Windows 10 or if you are like me you are on the Insider Program you may find yourself with many 450MB recovery partitions.  With a traditional disk that may not be a problem but with relatively smaller SS…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now