Scripts

Add a Windows computer to the domain:

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

strComputer = "."

strDomain = "example.com"

strUser = inputbox("Sys Account Name")

strPassword = inputbox("Sys Account Password")

strLocation = "Something"

strWorkstationDesc = ""

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set objNetwork = CreateObject("WScript.Network")

Set objFSO = CreateObject("Scripting.FileSystemObject")

'Set objLogFile = objFSO.OpenTextFile ("c:\" & computerName & year(date()) & month(date()) & day(date()) & hour(now()) & minute(now()) & ".log", 8, True)

Set wshell = CreateObject("WScript.Shell")

Set colSettings = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")

For Each objComputer in colSettings

if left(objComputer.Manufacturer,4) = "Dell" then

strManufacturer = "Dell"

else

strManufacturer = objComputer.Manufacturer

end if

strWorkstationDesc = strManufacturer & " " & trim(objComputer.Model) & " (" & strLocation & ")"

'Wscript.Echo strWorkstationDesc

Next

Set colChassis = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")

For Each objChassis in colChassis

For Each strChassisType in objChassis.ChassisTypes '(8-10 = laptop) (3-4 = Desktop)

if strChassisType > 2 and strChassisType < 5 then

'Workstation OU

ADPath = "OU=Workstations, OU=Computers, OU=Dublin, OU=EU, DC=example, DC=com"

'wscript.echo "Workstation OU " & ADPath

elseif strChassisType > 7 and strChassisType < 11 then

'Laptop OU

ADPath = "OU=Laptops, OU=Computers, OU=Dublin, OU=EU, DC=example, DC=com"

'wscript.echo "Laptop OU " & ADPath

end if

Next

Next

Set objNetwork = CreateObject("WScript.Network")

strComputer = objNetwork.ComputerName

'objLogFile.WriteLine(now() & " " & strComputer)

'objLogFile.WriteLine(now() & " " & ADPath)

'objLogFile.WriteLine(now() & " " & strWorkstationDesc)

Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")

ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, strPassword, strDomain & "\" & strUser, ADPath, JOIN_DOMAIN + ACCT_CREATE)

'msgbox("LDAP://CN=" & strComputer & ", " & ADPath)

'objLogFile.WriteLine(now() & " Add Computer to AD " & ReturnValue)

set objComputer = GetObject("LDAP://CN=" & strComputer & ", " & ADPath)

objComputer.Put "Description", strWorkstationDesc

objComputer.SetInfo

'objLogFile.WriteLine(now() & " Finished Running Post Install Script" )