Domain Join Script

As per one of the requirement in recent activity at Global IT Company, we have got the script which we can use to join a machine to domain and then restart the machine.

  • For Windows XP just need to run the script.
  • For Windows 7 we need to run CMD as administrator and then run the script.


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 = “Domain Name”
strPassword = “Password”
strUser = “Admiistrator”
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)
Dim objShell
Set objShell = WScript.CreateObject(“WScript.Shell”)
objShell.Run “C:\WINDOWS\system32\shutdown.exe -r -t 0”
 

One thought on “Domain Join Script

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s