Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

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
0
croag
Asked:
croag
  • 3
  • 3
  • 2
  • +1
4 Solutions
 
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now