Adding workgroup computer (Windows Server 2003 and Windows 2008) to domain using vbscript.

Hi All,

Could you please help me how to change workgroup to domain using vbscript for Windows Server 2003 and Windows Server 2008.
These are the below steps which we are manually adding workgroup computer to domain.

1. Right click My Computer and select Properties.

2. Then click Advanced system settings.

3. Go to Computer Name tab and click change.

4. Then select Domain and enter the Domain name.

5. Once the Domain is added, then click to More in the Computer Name tab and edit Primary DNS suffix of this computer.

6. Uncheck (Disable) Change primary DNS suffix when domain membership changes.

7. Reboot the system.

Could you please anyone to create a script for me as I need to manually add 76 servers

Any assistance could offer would be greatly appreciated.

Attached screenshot for examples.
 1 2
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Neil RussellTechnical Development LeadCommented:
Dont need a script, use NETDOM.EXE
It is possible to use NETDOM utility to join to Domain using command line.

You can visit following link to learn more.

Hope this helps
Alternatively you can use WMI in VBScript
strDomain = "DOMAIN_NAME"
strUser = "USER_NAME"
strPassword = "PASSWORD"
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

Open in new window

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

jashir101Author Commented:
This is not what im looking for. I have clearly mentioned the details in the title and question.

Can u please tell me what i have to give in OU and make a script it will prompt to ask which domain is to be added as we are using 3 domains.

Also i want to uncheck Change primary DNS suffix when domain membership changes

So please help me.
Neil RussellTechnical Development LeadCommented:

Where was the bit about 3 domain?

I find you manner rude and as far as I am concerened you can go find your own script.  Were to help and offer the best advice based on THE QUESTION DETAILS.

You could add following reference code to ask the user and apply applicable Domain

Set objStdOut = WScript.StdOut
objStdOut.Write "Which Domain do you want to connect to?" & vbCRLF
objStdOut.Write "1. domain 1" & vbCRLF
objStdOut.Write "2. domain 2" & vbCRLF
userOption = Wscript.StdIn.ReadLine
if userOption = 1 Then
	strOU = "ou=COMPUTERS,ou=TESTOU,dc=domain1,dc=COM"
ENd If
if userOption = 2 Then
	strOU = "ou=COMPUTERS,ou=TESTOU,dc=domain2,dc=COM"
ENd If

if userOption = 3 Then
	strOU = "ou=COMPUTERS,ou=TESTOU,dc=domain1,dc=COM"
ENd If
if userOption = 4 Then
	strOU = "ou=COMPUTERS,ou=TESTOU,dc=domain1,dc=COM"
ENd If

Open in new window

Hope this helps

For list of various Join options visit :
jashir101Author Commented:
I am not getting proper solution. Please help me on this.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2003

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.