Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Dim strDomain, strUser, strPassword, strOU, varCASE, strModel, SystemName, strUserType
- Dim objNetwork, strComputer, objComputer, lngReturnValue, objShell, tmpObj, tmpItem, MakeModel
- SystemName = "localhost"
- strUserType = "Staff"
- 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
- ' Prompt for credentials.
- strDomain = "explore.explorecharterschool.org"
- strUser = "admins"
- strPassword = "2enterplz!"
- ' Retrieve NetBIOS name of local computer.
- Set objNetwork = CreateObject("WScript.Network")
- strComputer = objNetwork.ComputerName
- ' Compare first 3 characters of strComputer string for CASE/select statement
- varCASE = ucase(left(strComputer,3))
- ' Case switch to place computer in specified OU
- Select CASE varCASE
- CASE "E00"
- if instr(strUserType,"Staff") then
- strOU = "OU=Esi_Computers,OU=ESI,DC=explore,DC=explorecharterschool,DC=org"
- else
- Wscript.Echo "something is wrong with joining machine to correct OU"
- end if
- CASE "E01"
- if instr(strUserType,"Student") then
- strOU = "OU=Exp_Student_Computers,OU=Explore Charter School,DC=explore,DC=explorecharterschool,DC=org"
- elseif instr(strUserType,"Staff") then
- strOU = "OU=Exp_Computers,OU=Explore Charter School,DC=explore,DC=explorecharterschool,DC=org"
- else
- Wscript.Echo "something is wrong with joining machine to correct OU"
- end if
- CASE "E02"
- if instr(strUserType,"Student") then
- strOU = "OU=Emp_Student_Computers,OU=Empower Charter School,DC=explore,DC=explorecharterschool,DC=org"
- elseif instr(strUserType,"Staff") then
- strOU = "OU=Emp_Computers,OU=Empower Charter School,DC=explore,DC=explorecharterschool,DC=org"
- else
- Wscript.Echo "something is wrong with joining machine to correct OU"
- end if
- CASE "E03"
- if instr(strUserType,"Student") then
- strOU = "OU=Exc_Student_Computers,OU=Excel Charter School,DC=explore,DC=explorecharterschool,DC=org"
- elseif instr(strUserType,"Staff") then
- strOU = "OU=Exc_Computers,OU=Excel Charter School,DC=explore,DC=explorecharterschool,DC=org"
- else
- Wscript.Echo "something is wrong with joining machine to correct OU"
- end if
- CASE "E04"
- if instr(strUserType,"Student") then
- strOU = "OU=Exd_Student_Computers,OU=Exceed Charter School,DC=explore,DC=explorecharterschool,DC=org"
- elseif instr(strUserType,"Staff") then
- strOU = "OU=Exd_Computers,OU=Exceed Charter School,DC=explore,DC=explorecharterschool,DC=org"
- else
- Wscript.Echo "something is wrong with joining machine to correct OU"
- end if
- CASE "E05"
- if instr(strUserType,"Student") then
- strOU = "OU=Exc_Upper_Student_Computers,OU=Excel Upper Charter School,DC=explore,DC=explorecharterschool,DC=org"
- elseif instr(strUserType,"Staff") then
- strOU = "OU=Exc_Upper_Computers,OU=Excel Upper Charter School,DC=explore,DC=explorecharterschool,DC=org"
- else
- Wscript.Echo "something is wrong with joining machine to correct OU"
- end if
- CASE Else
- wscript.Echo "The Machine did NOT join the right OU!!!!!"
- end Select
- Set objComputer = GetObject("winmgmts:" _
- & "{impersonationLevel=Impersonate,authenticationLevel=Pkt}!\\" & _
- strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
- strComputer & "'")
- lngReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
- strPassword, strDomain & "\" & strUser, strOU, _
- JOIN_DOMAIN + ACCT_CREATE)
- Wscript.Echo "ReturnValue = " & CStr(lngReturnValue)
- wscript.Echo "Computer Name = " & CStr(strComputer)
- Select Case lngReturnValue
- Case 0
- Wscript.Echo "Success joining computer to the domain!"
- Case 5
- Wscript.Echo "Access is denied"
- Case 87
- Wscript.Echo "The parameter is incorrect"
- Case 110
- Wscript.Echo "The system cannot open the specified object"
- Case 1323
- Wscript.Echo "Unable to update the password"
- Case 1326
- Wscript.Echo "Logon failure: unknown username or bad password"
- Case 1355
- Wscript.Echo "The specified domain either does not exist or could not be contacted"
- Case 2224
- Wscript.Echo "The account already exists"
- Case 2691
- Wscript.Echo "The machine is already joined to the domain"
- Case 2692
- Wscript.Echo "The machine is not currently joined to a domain"
- Case Else
- Wscript.Echo "Unknown error"
- End Select
- ' Reboots PC in Zero Seconds
- Set objShell = WScript.CreateObject("WScript.Shell")
- objShell.Run "C:\WINDOWS\system32\shutdown.exe -r -t 00"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement