Solved

join a computer to the domain with a script

Posted on 2009-06-28
18
374 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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
 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Google  (Get  Users Email) 2 136
Need script to search multiple files in one drive 13 55
Need help Creating PowerShell Script 5 54
Convert .csv to tab delimited text 11 34
Log files are useful in diagnosing and repairing problems.  This is a list of common log files and their standard locations that I've compiled.   While this is not exhaustive, it is a pretty good list that I've found to be useful.  I may update it f…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

860 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