Solved

join a computer to the domain with a script

Posted on 2009-06-28
18
366 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

The way I use Experts Exchange to assist me in analyzing and diagnosing a problem is I first enter a Verbose Question at Experts Exchange like: Office 2007 will hang when opening and saving files I then launch WordPad (any text editor will do) an…
Ever notice how you can't use a new drive in Windows without having Windows assigning a Disk Signature?  Ever have a signature collision problem (especially with Virtual Machines?)  This article is intended to help you understand what's going on and…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

746 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

10 Experts available now in Live!

Get 1:1 Help Now