Video Screencast Help
Search Video Help Close Back
to help
New in the Rewards Catalog: Vouchers for "Symantec Technical Specialist" and "Symantec Certified Specialist" exams.

Using VBScript\WMI to Join a Computer to a Domain

Updated: 07 Aug 2008
Dan Waksman's picture
0 0 Votes
Login to vote

Previously I had been using netdom.exe from the Server 2003 Support Tools to join computers to a domain automatically. However, using VBScript and WMI is slightly easier because it doesn't require any extra files.

The example below will create a new Computer object in the Active Directory OU that you specify. The following variables should be set according to your own environment:

strDomain - domain name
strUser - user id with rights to create a computer object
strPassword - the password for the user id specified in strUser
strOU - the Active Directory OU where the Computer object will be created, in FQDN format

Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
 
strDomain = "DOMAIN_NAME"
strUser = "USER_NAME"
strPassword = "PASSWORD"
strOU = "ou=COMPUTERS,ou=TESTOU,dc=COMPANY,dc=COM"
 
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
 
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")

objComputer.JoinDomainOrWorkGroup strDomain, strPassword, strDomain & "\" & strUser, strOU, JOIN_DOMAIN + ACCT_CREATE