Results 1 to 2 of 2

Thread: Script to add a machine to domain

  1. #1
    Join Date
    May 2010
    Posts
    1

    Script to add a machine to domain

    I need a script that will add a machine to the domain. The machines that I want to run this script on already have computer accounts created in active directory and are named properly. They are just not on the domain.

  2. #2
    Join Date
    Jun 2006
    Posts
    623

    Re: Script to add a machine to domain

    Try the below script to join a computer to a network remotely:

    Code:
    Option Explicit
     
    Dim objNetwork, strDomainName, strComputer
    Dim strRemoteAdminUser, strRemoteAdminPass, strAdminUser, strAdminPass
    Dim objShell, strCommand
     
    Set objNetwork = CreateObject("WScript.Network")
    Set objShell = CreateObject("WScript.Shell")
    strDomainName = objNetwork.UserDomain
     
    strComputer = InputBox("Enter the Computer Name or IP Address:", "Computer")
    strRemoteAdminUser = InputBox("Enter the local administrator account name for " & strComputer & ":", "Admin User Account on " & strComputer, "Administrator")
    strRemoteAdminPass = InputBox("Enter the local password for " & strComputer & "\" & strRemoteAdminUser & ":", "Local Admin Password")
    strAdminUser = InputBox("Enter the domain account for " & strDomainName & " to join the computer to the domain with:", "Domain Admin User Account", "Administrator")
    strAdminPass = InputBox("Enter the password for " & strDomainName & "\" & strAdminUser & ":", "Domain Admin User Password")
    If Ping(strComputer) = True Then
          ' IF THE FIRST COMMAND FAILS, TRY USING THE SECOND COMMAND TO CONNECT TO THE REMOTE MACHINE WITH EXPLICIT CREDENTIALS
          ' Also, you can change the cmd /k to cmd /c and change objShell.Run strCommand, 1, True to objShell.Run strCommand, 0, True
          ' to hide  the command prompt, but do not use cmd /k and 0, otherwise an open command prompt will stay hidden.
          strCommand = "cmd /k NETDOM JOIN " & strComputer & " /Domain:" & strDomainName & " /userD:" & strDomainName & "\" & strAdminUser & " /passwordD:" & strAdminPass & " /userO:" & strRemoteAdminUser & " /passwordO:" & strRemoteAdminPass & " /REBOOT"
          'strCommand = "cmd /k NETDOM JOIN " & strComputer & " /Domain:" & strDomainName & " /userD:" & strDomainName & "\" & strAdminUser & " /passwordD:" & strAdminPass & " /REBOOT"
          strCommand = InputBox("Prompt", "Title", strCommand)
          objShell.Run strCommand, 1, True
    Else
          MsgBox strComputer & " could not be pinged."
    End If
     
    MsgBox "Done"
     
    Function Ping(strComputer)
    	Dim objShell, boolCode
    	Set objShell = CreateObject("WScript.Shell")
    	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
    	If boolCode = 0 Then
    		Ping = True
    	Else
    		Ping = False
    	End If
    End Function

Similar Threads

  1. Running script on remote machine
    By SuderMan in forum Windows Server Help
    Replies: 12
    Last Post: 25-08-2010, 06:51 PM
  2. VBS Script To Get Machine Information And Send To Excel
    By drewdog in forum Software Development
    Replies: 4
    Last Post: 31-07-2010, 07:07 PM
  3. Script execution machine available by mail
    By HardWeaR in forum Software Development
    Replies: 3
    Last Post: 11-12-2009, 02:01 PM
  4. Check if process is running on Local Machine using VB script
    By Aspen in forum Software Development
    Replies: 3
    Last Post: 03-09-2009, 09:46 PM
  5. domain logon script does not run
    By Onetoomany in forum Windows Server Help
    Replies: 4
    Last Post: 11-02-2008, 05:37 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,035,619.60582 seconds with 16 queries