Adding a computer to a domain by way of a VBS script?

Does anyone have a script that will add a computer to a 'ourdomain' ...and we can have our domain admin and pw in the VBS script (or any other script)? So..we can essentially just walk to the computer, click the file, and it adds the computer to the domain?


And restarts the computer if possible? Anyone heard of this?


This should work with windows 2000k and/or xp clients. (or 2 different scripts for each client os if possible)

Thanks,

croag
LVL 1
croagIdeator Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
georgecooldudeCommented:
I dont know a vb one. But I use this batch one. Its fine if you run it locally from the computer, Just beaware the password can be seen so make sure no one is looking over your shoulder.



Join Domain
______________
netdom join %computername% /domain:<newdomain> /userd:<domain_admin> /passwordd:<domain_admin_pass>
pause
______________


Remove Domain
_______________
netdom remove %computername% /domain:<currentdomain> /userd:<domain_admin> /passwordd:<domain_admin_pass>
pause
_______________


Add the following from netdom... to ...pause into a notepad and save it as joindomain.bad and removedomain.bat

It worked well for me on most computers. I don't know any vbscript. And Im not too sure how to reboot from a bat file. Maybe try adding "reboot" onto the next line?
0
georgecooldudeCommented:
You might also need a DNS script aswell.

This is a vb script one someone made for me:

______________________________
Const strNewDNS1 = "0.0.0.0"
Const strNewDNS2 = "0.0.0.0"


Set objNICs = GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_NetworkAdapterConfiguration")

For Each objNIC In objNICs
    If objNIC.IPEnabled Then
     objNIC.SetDNSServerSearchOrder Array(strNewDNS1, strNewDNS2)
    End If
Next
______________________________

Oh and my above suggestion makes use of a program called netdom.exe - I think its in the win2k3 support tools.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

tmorrison3Commented:
From the book listed below - has tons of great stuff - http://www.rallenhome.com/books/adcookbook/code.html

' This VBScript code joins a computer to a domain.

' ---------------------------------------------------------------
' From the book "Active Directory Cookbook" by Robbie Allen
' Publisher: O'Reilly and Associates
' ISBN: 0-596-00466-4
' Book web site: http://rallenhome.com/books/adcookbook/code.html
' ---------------------------------------------------------------

' ------ SCRIPT CONFIGURATION ------
strComputer     = "<ComputerName>"      ' e.g. joe-xp
strDomain       = "<DomainName>"        ' e.g. rallencorp.com
strDomainUser   = "<DomainUserUPN>"     ' e.g. administrator@rallencorp.com
strDomainPasswd = "<DomainUserPasswd>"
strLocalUser    = "<ComputerAdminUser>" ' e.g. administrator
strLocalPasswd  = "<ComputerUserPasswd>"
' ------ END CONFIGURATION ---------

'########################
' Constants
'########################
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

'###########################
' Connect to Computer
'###########################
set objWMILocator = CreateObject("WbemScripting.SWbemLocator")
objWMILocator.Security_.AuthenticationLevel = 6
set objWMIComputer = objWMILocator.ConnectServer(strComputer,  _
                                               "root\cimv2", _
                                                 strLocalUser, _
                                                 strLocalPasswd)
set objWMIComputerSystem = objWMIComputer.Get( _
                               "Win32_ComputerSystem.Name='" & _
                               strComputer & "'")

'###########################
' Join Computer
'###########################
rc = objWMIComputerSystem.JoinDomainOrWorkGroup(strDomain, _
                                                strDomainPasswd, _
                                                strDomainUser, _
                                                vbNullString, _
                                                JOIN_DOMAIN)
if rc <> 0 then
    WScript.Echo "Join failed with error: " & rc
else
    WScript.Echo "Successfully joined " & strComputer & " to " & strDomain
end if

0
David LeeCommented:
tmorrison3,

I gave a link to the same book and the same code in my post.
0
tmorrison3Commented:
I saw that - sorry - I will read a little more diligently next time
0
David LeeCommented:
It's okay, I've done the same thing myself.
0
jottmanCommented:
I have tried this script, but I keep getting a error.

Error:The RPC server is unavailable
Code: 800706BA
Source: SWbemLocator

Any ideas as to what is wrong?

0
georgecooldudeCommented:
jottman which one? Maybe start your own question so all experts can be invloved in it. :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows 2000

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.