VBS script will not execute on Server 2012 R2 or Windows 8.1 RRS feed

  • Question

  • I have inherited a script to create user accounts. The script worked fine using Server 2008 R2 or Windows 7. We've updated our DC to Server 2012 and I cannot get the script to actually create the student accounts. I'm open to any suggestions to help resolve this.  
    Thursday, February 4, 2016 6:16 PM


All replies

  • Not enough information.  There is no reason for a script that is written correctly to nor work.

    I recommend that you contact a consultant to help you understand how a script works and t help trouble shoot your installation.

    I recommend that yu sue the tools on WS2012R2 to create and manage users.  They are more powerful and easier to use.


    Thursday, February 4, 2016 6:24 PM
  • I apologize for being vague. Here is a copy of the script. Again, nothing was changed between the server migration, just copy and pasted the script to the new server. The csv it refrences is created by another .vbs script that does execute properly. This script executes but does not actually create the account in Active Directory.

    On Error Resume Next
    ' Bind to Active Directory, Users container.
    Set objRootLDAP = GetObject("LDAP://rootDSE")
    Const ForReading = 1
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile("AllNewStudentAccounts.csv", ForReading)
    intCount = 0
    Do Until objTextFile.AtEndOfStream
        strNextLine = objTextFile.Readline
        arrNewAccountInfo = Split(strNextLine , ",")
    	strUserName = arrNewAccountInfo(0)
    	strStateNum = arrNewAccountInfo(3)
    	strPassword = arrNewAccountInfo(6)
    	strGradYear = arrNewAccountInfo(4)
    	strSchool = arrNewAccountInfo(5)
    	charFirstLetter = Left(strUserName,1)
    	Select Case charFirstLetter 
    	Case "A","B","C","D","E","F","G","H","I"
    		strInitials = "/A-I/"
    	Case "J","K","L","M","N","O","P","Q","R"
    		strInitials = "/J-R/"
    	Case "S","T","U","V","W","X","Y","Z"
    		strInitials = "/S-Z/"
    	End Select
    	strSchoolFullName = ""
    	Select Case strSchool
    	Case "S1"
    '		strSchoolFullName = "School1"
    		strSchoolFullName = "S1Students"
    	Case "S2"
    '		strSchoolFullName = "School2"
    		strSchoolFullName = "S2Students"
    	Case "S3"
    '		strSchoolFullName = "School3"
    		strSchoolFullName = "S3Students"
    	Case "S4"
    '		strSchoolFullName = "School4"
    		strSchoolFullName = "S4Students"
    	End Select
    	strMail = strUserName & ""
    	strHomePage = ""
    	strOU = "OU=" & strSchoolFullName & ",OU=Students,OU=TESTSCHOOL,OU=Schools,OU=Domain Users,"
    	Set objOU = GetObject("LDAP://" & strOU & objRootLDAP.Get("defaultNamingContext"))
    	' Build the actual User.
    	Set objUser = objOU.Create("User", "cn=" & strUserName)
    	objUser.samAccountName = strUserName
    	objUser.userPrincipalName = strUserName
    	objUser.givenName = strUserName
    	objUser.displayName = strUserName
    	objUser.description = strGradYear
    	objUser.physicalDeliveryOfficeName = strSchool
    	objUser.mail = strMail
    	objUser.wWWHomePage = strHomePage
    	objUser.title = "Student"
    	objUser.department = strSchool
    	objUser.SetInfo = strStateNum
    	objUser.SetPassword strPassword
    	objUser.AccountDisabled = True
    	intCount = intCount + 1
    WScript.Echo "Finished with " & intCount & " Accounts!"

    Thursday, February 4, 2016 6:32 PM
  • Start by removing "On Error Resume Next" and fix the errors.


    • Marked as answer by JulianTech Thursday, February 4, 2016 7:31 PM
    Thursday, February 4, 2016 6:46 PM
  • I feel silly. Thanks for the suggestion. I did that and have an access denied error from Active Directory. I wish I had tried this sooner. Thanks again for the help. 
    Thursday, February 4, 2016 7:31 PM
  • I am glad it turned out to be something simple.

    Don't use On error as it can get you in trouble blindly as you have seen.


    Thursday, February 4, 2016 8:21 PM