Solved

join a computer to the domain with a script

Posted on 2009-06-28
18
376 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
powershell switch statement 7 32
Powershell GUI 11 63
Move files based on file names? 8 27
Cannot exit IF statement in PowerShell 4 23
This is a little timesaver I have been using for setting up Microsoft Small Business Server (SBS) in the simplest possible way. It may not be appropriate for every customer. However, when you get a situation where the person who owns the server is i…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

749 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