Advertisement
Guest User

!JoinDomain-EXNSTAFF.vbs |Explorecharterschool_NYC domainreg

a guest
Jan 12th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. Dim strDomain, strUser, strPassword, strOU, varCASE, strModel, SystemName, strUserType
  4. Dim objNetwork, strComputer, objComputer, lngReturnValue, objShell, tmpObj, tmpItem, MakeModel
  5.  
  6.  
  7. SystemName = "localhost"
  8. strUserType = "Staff"
  9.  
  10. Const JOIN_DOMAIN = 1
  11. Const ACCT_CREATE = 2
  12. Const ACCT_DELETE = 4
  13. Const WIN9X_UPGRADE = 16
  14. Const DOMAIN_JOIN_IF_JOINED = 32
  15. Const JOIN_UNSECURE = 64
  16. Const MACHINE_PASSWORD_PASSED = 128
  17. Const DEFERRED_SPN_SET = 256
  18. Const INSTALL_INVOCATION = 262144
  19.  
  20. ' Prompt for credentials.
  21. strDomain = "explore.explorecharterschool.org"
  22. strUser = "admins"
  23. strPassword = "2enterplz!"
  24.  
  25. ' Retrieve NetBIOS name of local computer.
  26. Set objNetwork = CreateObject("WScript.Network")
  27. strComputer = objNetwork.ComputerName
  28.  
  29. ' Compare first 3 characters of strComputer string for CASE/select statement
  30. varCASE = ucase(left(strComputer,3))
  31.  
  32. ' Case switch to place computer in specified OU
  33. Select CASE varCASE
  34. CASE "E00"
  35.      if instr(strUserType,"Staff") then
  36.     strOU = "OU=Esi_Computers,OU=ESI,DC=explore,DC=explorecharterschool,DC=org"
  37.      else
  38.         Wscript.Echo "something is wrong with joining machine to correct OU"
  39.      end if
  40. CASE "E01"
  41.      if instr(strUserType,"Student") then
  42.     strOU = "OU=Exp_Student_Computers,OU=Explore Charter School,DC=explore,DC=explorecharterschool,DC=org"
  43.      elseif instr(strUserType,"Staff") then
  44.         strOU = "OU=Exp_Computers,OU=Explore Charter School,DC=explore,DC=explorecharterschool,DC=org"
  45.      else
  46.         Wscript.Echo "something is wrong with joining machine to correct OU"
  47.      end if
  48. CASE "E02"
  49.      if instr(strUserType,"Student") then
  50.     strOU = "OU=Emp_Student_Computers,OU=Empower Charter School,DC=explore,DC=explorecharterschool,DC=org"
  51.      elseif instr(strUserType,"Staff") then
  52.         strOU = "OU=Emp_Computers,OU=Empower Charter School,DC=explore,DC=explorecharterschool,DC=org"
  53.      else
  54.         Wscript.Echo "something is wrong with joining machine to correct OU"
  55.     end if
  56. CASE "E03"
  57.      if instr(strUserType,"Student") then
  58.     strOU = "OU=Exc_Student_Computers,OU=Excel Charter School,DC=explore,DC=explorecharterschool,DC=org"
  59.      elseif instr(strUserType,"Staff") then
  60.         strOU = "OU=Exc_Computers,OU=Excel Charter School,DC=explore,DC=explorecharterschool,DC=org"
  61.      else
  62.         Wscript.Echo "something is wrong with joining machine to correct OU"
  63.      end if
  64. CASE "E04"
  65.      if instr(strUserType,"Student") then
  66.     strOU = "OU=Exd_Student_Computers,OU=Exceed Charter School,DC=explore,DC=explorecharterschool,DC=org"
  67.      elseif instr(strUserType,"Staff") then
  68.         strOU = "OU=Exd_Computers,OU=Exceed Charter School,DC=explore,DC=explorecharterschool,DC=org"
  69.      else
  70.         Wscript.Echo "something is wrong with joining machine to correct OU"
  71.      end if
  72. CASE "E05"
  73.      if instr(strUserType,"Student") then
  74.     strOU = "OU=Exc_Upper_Student_Computers,OU=Excel Upper Charter School,DC=explore,DC=explorecharterschool,DC=org"
  75.      elseif instr(strUserType,"Staff") then
  76.         strOU = "OU=Exc_Upper_Computers,OU=Excel Upper Charter School,DC=explore,DC=explorecharterschool,DC=org"
  77.      else
  78.         Wscript.Echo "something is wrong with joining machine to correct OU"
  79.      end if
  80. CASE Else
  81.      wscript.Echo "The Machine did NOT join the right OU!!!!!"
  82. end Select
  83.  
  84. Set objComputer = GetObject("winmgmts:" _
  85.     & "{impersonationLevel=Impersonate,authenticationLevel=Pkt}!\\" & _
  86.     strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
  87.         strComputer & "'")
  88.  
  89. lngReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
  90.     strPassword, strDomain & "\" & strUser, strOU, _
  91.         JOIN_DOMAIN + ACCT_CREATE)
  92.  
  93. Wscript.Echo "ReturnValue = " & CStr(lngReturnValue)
  94. wscript.Echo "Computer Name = " & CStr(strComputer)
  95.  
  96. Select Case lngReturnValue
  97.     Case 0
  98.         Wscript.Echo "Success joining computer to the domain!"
  99.     Case 5
  100.         Wscript.Echo "Access is denied"
  101.     Case 87
  102.         Wscript.Echo "The parameter is incorrect"
  103.     Case 110
  104.         Wscript.Echo "The system cannot open the specified object"
  105.     Case 1323
  106.         Wscript.Echo "Unable to update the password"
  107.     Case 1326
  108.         Wscript.Echo "Logon failure: unknown username or bad password"
  109.     Case 1355
  110.         Wscript.Echo "The specified domain either does not exist or could not be contacted"
  111.     Case 2224
  112.         Wscript.Echo "The account already exists"
  113.     Case 2691
  114.         Wscript.Echo "The machine is already joined to the domain"
  115.     Case 2692
  116.         Wscript.Echo "The machine is not currently joined to a domain"
  117.     Case Else
  118.         Wscript.Echo "Unknown error"
  119. End Select
  120.  
  121. ' Reboots PC in Zero Seconds
  122. Set objShell = WScript.CreateObject("WScript.Shell")
  123. objShell.Run "C:\WINDOWS\system32\shutdown.exe -r -t 00"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement