Go Back   TechArena Community > Software > Windows Software
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 11-05-2010
Member
 
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.
Reply With Quote
  #2  
Old 11-05-2010
Member
 
Join Date: Jun 2006
Posts: 620
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
Reply With Quote
Reply

  TechArena Community > Software > Windows Software
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Script to add a machine to domain"
Thread Thread Starter Forum Replies Last Post
Running script on remote machine SuderMan Windows Server Help 12 25-08-2010 06:51 PM
VBS Script To Get Machine Information And Send To Excel drewdog Software Development 4 31-07-2010 07:07 PM
Script execution machine available by mail HardWeaR Software Development 3 11-12-2009 02:01 PM
Check if process is running on Local Machine using VB script Aspen Software Development 3 03-09-2009 09:46 PM
domain logon script does not run Onetoomany Windows Server Help 4 11-02-2008 05:37 AM


All times are GMT +5.5. The time now is 10:51 PM.