Print this post Print this post

How to add computers do Active Directory remotely

How to add computers do Active Directory remotely?

Sometimes we must add many computers to Active Directory and we don?t have time to do this or computers are located in other City.

This post explains how to add computers to Active Directory remotely without touch this computers.

Step 1. Prepare text file contains computers IP addresses or computers names.

01

Step 2. Download PsTools from Microsoft

Step 3. Extract pstools.zip file and copy psexec.exe and psshutdown.exe files to the same folder You place computers.txt file. (In my example this is disc c:\)

Psexec – execute programs on remote systems

Psshutdown ? reboot or shutdown remote systems

Step 4. Create two scripts in VBScript or use scripts from Microsoft site

First script is used to copy files from one computer to many computers. List of computers are prepared in compters.txt files.

I am using Microsoft script named copy.vbs:

Const ForReading = 1

Const OverwriteExisting = TRUE

?

Set objFSO = CreateObject(”Scripting.FileSystemObject”)

Set objFile = objFSO.OpenTextFile(”C:\Computers.txt”)

?

Do Until objFile.AtEndOfStream

? ? ? strComputer = objFile.ReadLine

? ? ? strRemoteFile = “\\” & strComputer & “\C$\add_domain.vbs”

? ? ? objFSO.CopyFile “C:\add_domain.vbs”, strRemoteFile, OverwriteExisting

Loop

Second script is used to add computer to Active Directory.

I am using Microsoft script named add_domian.vbs:

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 = “CONTOSO

strPassword = “test!@#

strUser = “Admin

?

Set objNetwork = CreateObject(”WScript.Network”)

strComputer = objNetwork.ComputerName

?

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)

?

Step 5. If you have all files in one folder and you are logged on server with Admin account run copy.vbs script (this copy script add_domain.vbs to all computers),

C:\>copy.vbs

next run psexec.exe @c:\computers.txt cmd.exe /c c:\add_domain.vbs (this run script add_domain.vbs on all computers remotely),

C:\>psexec.exe @c:\computers.txt cmd.exe /c c:\add_domain.vbs

PsExec v1.94 – Execute processes remotely
Copyright (C) 2001-2008 Mark Russinovich
Sysinternals –
www.sysinternals.com

\\10.10.11.102:

cmd.exe exited on 10.10.11.102 with error code 0.
\\10.10.11.103:

cmd.exe exited on 10.10.11.103 with error code 0.

next run psshutdown.exe @c:\computers.txt ?r (this command reboot all computers).

C:\>psshutdown.exe @c:\computers.txt -r

PsShutdown v2.52 – Shutdown, logoff and power manage local and remote systems
Copyright (C) 1999-2006 Mark Russinovich
Sysinternals –
www.sysinternals.com

\\10.10.11.102:
10.10.11.102 is scheduled to reboot in 00:00:20.

\\10.10.11.103:
10.10.11.103 is scheduled to reboot in 00:00:20.

Step 6. Verify Active Directory by runing Active Directory User and Computers tools

?

?

02

Remember Admin password to all computers must be the same.

Musisz być logged in żeby skomentować ten wpis.