none
Subscript out of Range RRS feed

  • Question

  • Hi All,

    Whenever I use the below script, I get an error that.

    E:\Files\ADScripts\EAusrrmv22.vbs(25, 1) Microsoft VBScript runtime error: Subscript out of range

    I have checked on line 25, 1, couldn't found anything other than WScript.Arguments(2)

    ============================================================================

    Option Explicit 

    Const ADS_SCOPE_SUBTREE = 8 'How far down the tree you want to search
    Const ForAppending = 8

    Dim objRootDSE, objNewOU, objMoveUser, objOldOU, objFSO
    Dim objConnection, objCommand, objRecordSet, strDeleteDays, strDatetxt, ObjDC
    Dim UserDN, ObjUser, strDNSDomain, strQuery, strOldOU, objArgs, ADS_UF_ACCOUNTDISABLE
    Dim objLogon, strWeeks, strDays, intLogonTime, objFromOU, objToOU, strDeleteQuery
    Dim intLLTS, intReqCompare, ADVersion, intUAC, Uglyinfo, MoreUgly, intReqDeleteCompare, objTextFile

    ADVersion = "2003" 
    'ADVersion = "2000" 

    ' Gather the information from the arguments in the commandline.
    strDays = 90
    strDeleteDays = 180
    strDatetxt = "E:\Files\ADScripts\EA_User_Move.txt"

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile (strDatetxt, ForAppending, True)
    Set objArgs = WScript.Arguments
    objFromOU = WScript.Arguments(0) & ",dc=XX,dc=YY,dc=com"  'What Domain and OU are you pulling from
    objToOU = WScript.Arguments(1) & ",dc=XX,dc=YY,dc=com" 'Where is your Retired OU.
    objDC = WScript.Arguments(2)
    Set objNewOU = GetObject("LDAP://" & objToOU)

    ' Use ADO to search Active Directory for all Users
    Set objConnection      = CreateObject("ADODB.Connection") 
    Set objCommand         = CreateObject("ADODB.Command") 
    objConnection.Provider = "ADsDSOObject" 
    objConnection.Open "Active Directory Provider" 
    Set objCommand.ActiveConnection = objConnection 
    objCommand.Properties("Page Size") = 1000 
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 


    '-------------------- Begin Move Section -------------------------------
    On Error Resume Next
    strQuery = "SELECT distinguishedName FROM 'LDAP://" & objDC & "/" & objFromOU & "' WHERE objectCategory = 'User'"
    'strQuery = "SELECT distinguishedName,lastlogontimestamp FROM 'LDAP://" & objFromOU & "' WHERE objectCategory = 'User'"
    objCommand.CommandText = strQuery
    Set objRecordSet = objCommand.Execute
    objTextFile.WriteLine("90 day inactive users disabled from " & objFromOU)
    objRecordSet.MoveFirst 
    Do Until objRecordSet.EOF 
       UserDN = objRecordSet.Fields("distinguishedName").Value 
       Set ObjUser = GetObject("LDAP://" & UserDN) 
       ' Begin calculation 
       If ADVersion = "2003" Then 
          Set objLogon = ObjUser.Get("lastlogonTimeStamp") 
       Else 
          set objLogon = ObjUser.Get("lastLogon") 
       End If 
       intLogonTime = objLogon.HighPart * (2^32) + objLogon.LowPart 
       intLogonTime = intLogonTime / (60 * 10000000) 
       intLogonTime = intLogonTime / 1440
       intLLTS = intLogonTime + #1/1/1601# 
       intReqCompare = Now - strDays 
       If intLLTS < intReqCompare Then 
            Uglyinfo = ObjUser.cn
            MoreUgly = ObjUser.distinguishedName
            objTextFile.WriteLine(ObjUser.distinguishedName & " last logged on at " & intLLTS)
    intUAC = ObjUser.Get("userAccountControl")
    ObjUser.Put "userAccountControl", intUAC OR ADS_UF_ACCOUNTDISABLE
    ObjUser.AccountDisabled = True
    ObjUser.SetInfo
    ' Set objMoveUser = objNewOU.MoveHere ("LDAP://" & MoreUgly, "cn=" & Uglyinfo)
       End If 

       objRecordSet.MoveNext 
    Loop
    objTextFile.WriteLine("") 
    '-------------------- End Move Section -------------------------------


    Thanks HA

    Wednesday, September 17, 2014 6:01 AM

Answers

  • You passed less that three arguments.

    Ask the author of the script to give you instructions on how to use it.


    ¯\_(ツ)_/¯

    • Marked as answer by Anup Ghonge Monday, September 22, 2014 5:59 AM
    Wednesday, September 17, 2014 7:46 AM

All replies

  • You passed less that three arguments.

    Ask the author of the script to give you instructions on how to use it.


    ¯\_(ツ)_/¯

    • Marked as answer by Anup Ghonge Monday, September 22, 2014 5:59 AM
    Wednesday, September 17, 2014 7:46 AM
  • Unfortunately, author is out of organisation.. 

    Normally, it is configured in a scheduled task, since the task is not working, I tried to run manually via command prompt and got the above mentioned error.

    Can you please help me in this case?


    Thanks HA

    Wednesday, September 17, 2014 7:54 AM
  • You are not asking a scripting question.  You are asking for someone to fix a script for you.  THis forum is not a help desk for users.  It is a technical forum for scripters.

    You can learn how to read and use VBScript here: http://technet.microsoft.com/en-us/scriptcenter/dd772284

    If you are not a technician then you can call a consultant to assist.

    You can also just look at the three arguments and read what they are looking for.

     


    ¯\_(ツ)_/¯

    Wednesday, September 17, 2014 8:28 AM
  • Thank you Jrv, 

    There was changes OU changes in Active Directory, Which was causing the script to hang.

    With your link, I was able to find out the issue and was able to resolve.

    Thank you once again. 


    Thanks HA

    Monday, September 22, 2014 5:59 AM
  • That is good.  As you can see we would not be able to know that.  We can answer specific questions about scripting.


    ¯\_(ツ)_/¯

    Monday, September 22, 2014 7:18 AM