How to Combine Multiple vbs Scripts into 1 script?-VBForums
Results 1 to 5 of 5

Thread: How to Combine Multiple vbs Scripts into 1 script?

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2012
    Posts
    3

    How to Combine Multiple vbs Scripts into 1 script?

    Helly Guys,

    I Have This Script:
    Code:
    Option Explicit
    Dim objOU, objUser, objRootDSE
    Dim strContainer, strLastUser, strDNSDomain, intCounter, intAccValue
    Set objRootDSE = GetObject("LDAP://RootDSE")
    strDNSDomain = objRootDSE.Get("DefaultNamingContext")
    strContainer = "OU=Development - Secretary,OU=Development,OU=Regular - User's ,"
    intAccValue = 544
    strContainer = strContainer & strDNSDomain
    set objOU =GetObject("LDAP://" & strContainer )
    intCounter = 0
    For each objUser in objOU
        If objUser.class="user" then
        objUser.SetPassword "p@$$w0rd"
        objUser.SetInfo
        objUser.Put "userAccountControl", intAccValue
        objUser.SetInfo
        intCounter = intCounter +1
        strLastUser = objUser.Get ("name")
        objuser.Put "pwdLastSet", CLng(0)
        objuser.SetInfo
    End if
    next
    WScript.Echo intCounter & " Users change pwd next logon. Value " _
    & intAccValue
    WScript.Quit
    and this Script:
    Code:
    Option Explicit
    Dim objOU, objUser, objRootDSE
    Dim strContainer, strLastUser, strDNSDomain, intCounter, intAccValue
    Set objRootDSE = GetObject("LDAP://RootDSE")
    strDNSDomain = objRootDSE.Get("DefaultNamingContext")
    strContainer = "OU=Development - Manager,OU=Development,OU=Regular - User's ,"
    intAccValue = 544
    strContainer = strContainer & strDNSDomain
    set objOU =GetObject("LDAP://" & strContainer )
    intCounter = 0
    For each objUser in objOU
        If objUser.class="user" then
        objUser.SetPassword "p@$$w0rd"
        objUser.SetInfo
        objUser.Put "userAccountControl", intAccValue
        objUser.SetInfo
        intCounter = intCounter +1
        strLastUser = objUser.Get ("name")
        objuser.Put "pwdLastSet", CLng(0)
        objuser.SetInfo
    End if
    next
    WScript.Echo intCounter & " Users change pwd next logon. Value " _
    & intAccValue
    WScript.Quit
    How Can i Combine this 2 scripts to 1?

    The only line that im changing is this:
    in the first Script:
    Code:
    strContainer = "OU=Development - Secretary,OU=Development,OU=Regular - User's ,"
    and in the second script:
    Code:
    strContainer = "OU=Development - Manager,OU=Development,OU=Regular - User's ,"
    Can i Write this 2 line's in the same 1 script?

    thank you very much Guys

  2. #2
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    3,922

    Re: How to Combine Multiple vbs Scripts into 1 script?

    Define the containers in an array and then loop through list.
    Code:
    Option Explicit
    Dim objOU, objUser, objRootDSE
    Dim strLastUser, strDNSDomain, intCounter, intAccValue
    Dim strContainer(1), intCounter
    
        ' define the containers
        strContainer(0) = "OU=Development - Secretary,OU=Development,OU=Regular - User's ,"
        strContainer(1) = "OU=Development - Manager,OU=Development,OU=Regular - User's ,"
    
        
        Set objRootDSE = GetObject("LDAP://RootDSE")
        strDNSDomain = objRootDSE.Get("DefaultNamingContext")
        intAccValue = 544
        
        For intCounter = 0 to 1
            strContainer(intCounter) = strContainer(intCounter) & strDNSDomain
            set objOU =GetObject("LDAP://" & strContainer(intCounter))
            intCounter = 0
            For each objUser in objOU
                If objUser.class="user" then
                objUser.SetPassword "p@$$w0rd"
                objUser.SetInfo
                objUser.Put "userAccountControl", intAccValue
                objUser.SetInfo
                intCounter = intCounter +1
                strLastUser = objUser.Get ("name")
                objuser.Put "pwdLastSet", CLng(0)
                objuser.SetInfo
            End if
            next
        Next
        
        WScript.Echo intCounter & " Users change pwd next logon. Value " _
        & intAccValue
        WScript.Quit

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2012
    Posts
    3

    Re: How to Combine Multiple vbs Scripts into 1 script?

    Hey MarkT Thank you vey much for helping me, so i had trying to do like you wrote and now i have this script:
    Code:
    Option Explicit
    Dim objOU, objUser, objRootDSE
    Dim strLastUser, strDNSDomain, intCounter, intAccValue
    Dim strContainer(1), intCounter
    
        ' define the containers
        strContainer(0) = "OU=Support Manager's,OU=Help Desk - User's,OU=Adatum - User's,"
        strContainer(1) = "OU=Support Shift's,OU=Help Desk - User's,OU=Adatum - User's,"
        strContainer(2) = "OU=Development - Manager,OU=Development,OU=Adatum - User's,"
        strContainer(3) = "OU=Development - Secretary,OU=Development,OU=Adatum - User's,"
        strContainer(4) = "OU=Development - Team Manager's,OU=Development,OU=Adatum - User's,"
        strContainer(5) = "OU=Development - Employee's,OU=Development,OU=Adatum - User's,"
        strContainer(6) = "OU=Finance - Manager,OU=Finance,OU=Adatum - User's,"
        strContainer(7) = "OU=Finance - Secretary,OU=Finance,OU=Adatum - User's,"
        strContainer(8) = "OU=Finance - Team Manager's,OU=Finance,OU=Adatum - User's,"
        strContainer(9) = "OU=Finance - Employee's,OU=Finance,OU=Adatum - User's,"	
        strContainer(10) = "OU=Marketing - Manager,OU=Marketing,OU=Adatum - User's,"
        strContainer(11) = "OU=Marketing - Secretary,OU=Marketing,OU=Adatum - User's,"
        strContainer(12) = "OU=Marketing - Team Manager's,OU=Marketing,OU=Adatum - User's,"
        strContainer(13) = "OU=Marketing - Employee's,OU=Marketing,OU=Adatum - User's,"
        strContainer(14) = "OU=Sale's - Manager,OU=Sale's,OU=Adatum - User's,"
        strContainer(15) = "OU=Sale's - Secretary,OU=Sale's,OU=Adatum - User's,"
        strContainer(16) = "OU=Sale's - Team Manager's,OU=Sale's,OU=Adatum - User's,"
        strContainer(17) = "OU=Sale's - Employee's,OU=Sale's,OU=Adatum - User's,"
        strContainer(18) = "OU=General Manager's,OU=Adatum - User's,"		
    
        
        Set objRootDSE = GetObject("LDAP://RootDSE")
        strDNSDomain = objRootDSE.Get("DefaultNamingContext")
        intAccValue = 544
        
        For intCounter = 0 to 1
            strContainer(intCounter) = strContainer(intCounter) & strDNSDomain
            set objOU =GetObject("LDAP://" & strContainer(intCounter))
            intCounter = 0
            For each objUser in objOU
                If objUser.class="user" then
                objUser.SetPassword "p@$$w0rd"
                objUser.SetInfo
                objUser.Put "userAccountControl", intAccValue
                objUser.SetInfo
                intCounter = intCounter +1
                strLastUser = objUser.Get ("name")
                objuser.Put "pwdLastSet", CLng(0)
                objuser.SetInfo
            End if
            next
        Next
        
        WScript.Echo intCounter & " Users change pwd next logon. Value " _
        & intAccValue
        WScript.Quit
    But when im Trying to run in on my Server i get this Error:

    Line: 4
    char: 22
    Error: Name redefine
    Code: 800A0411
    Source: Microsoft VBScript compilation error

    What is the problame? what i'm doing wrong? thank you very much again for the help markT p@$$w0rd.txt

  4. #4
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    3,922

    Re: How to Combine Multiple vbs Scripts into 1 script?

    You have declared intCounter on both the third and forth line of code. Remove it from one of those lines.

    To use all your containers you will have to make a couple updates.

    You have declared strContainer with a UBound of 1. You need to update that to 18.
    Dim strContainer(18)

    Your loop is looping from strContainer 0 to 1. That needs to loop to 18 also.
    For intCounter = 0 to 18

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2012
    Posts
    3

    Re: How to Combine Multiple vbs Scripts into 1 script?

    Once Again Thank you very much MarkT for the help, i have been update the script :
    Code:
    Option Explicit
    Dim objOU, objUser, objRootDSE
    Dim strLastUser, strDNSDomain, intAccValue
    Dim strContainer(18),intCounter
    
        ' define the containers
        strContainer(0) = "OU=Support Manager's,OU=Help Desk - User's,OU=Adatum - User's,"
        strContainer(1) = "OU=Support Shift's,OU=Help Desk - User's,OU=Adatum - User's,"
        strContainer(2) = "OU=Development - Manager,OU=Development,OU=Adatum - User's,"
        strContainer(3) = "OU=Development - Secretary,OU=Development,OU=Adatum - User's,"
        strContainer(4) = "OU=Development - Team Manager's,OU=Development,OU=Adatum - User's,"
        strContainer(5) = "OU=Development - Employee's,OU=Development,OU=Adatum - User's,"
        strContainer(6) = "OU=Finance - Manager,OU=Finance,OU=Adatum - User's,"
        strContainer(7) = "OU=Finance - Secretary,OU=Finance,OU=Adatum - User's,"
        strContainer(8) = "OU=Finance - Team Manager's,OU=Finance,OU=Adatum - User's,"
        strContainer(9) = "OU=Finance - Employee's,OU=Finance,OU=Adatum - User's,"	
        strContainer(10) = "OU=Marketing - Manager,OU=Marketing,OU=Adatum - User's,"
        strContainer(11) = "OU=Marketing - Secretary,OU=Marketing,OU=Adatum - User's,"
        strContainer(12) = "OU=Marketing - Team Manager's,OU=Marketing,OU=Adatum - User's,"
        strContainer(13) = "OU=Marketing - Employee's,OU=Marketing,OU=Adatum - User's,"
        strContainer(14) = "OU=Sale's - Manager,OU=Sale's,OU=Adatum - User's,"
        strContainer(15) = "OU=Sale's - Secretary,OU=Sale's,OU=Adatum - User's,"
        strContainer(16) = "OU=Sale's - Team Manager's,OU=Sale's,OU=Adatum - User's,"
        strContainer(17) = "OU=Sale's - Employee's,OU=Sale's,OU=Adatum - User's,"
        strContainer(18) = "OU=General Manager's,OU=Adatum - User's,"		
    
        
        Set objRootDSE = GetObject("LDAP://RootDSE")
        strDNSDomain = objRootDSE.Get("DefaultNamingContext")
        intAccValue = 544
        
        For intCounter = 0 to 18
            strContainer(intCounter) = strContainer(intCounter) & strDNSDomain
            set objOU =GetObject("LDAP://" & strContainer(intCounter))
            intCounter = 0
            For each objUser in objOU
                If objUser.class="user" then
                objUser.SetPassword "p@$$w0rd"
                objUser.SetInfo
                objUser.Put "userAccountControl", intAccValue
                objUser.SetInfo
                intCounter = intCounter +1
                strLastUser = objUser.Get ("name")
                objuser.Put "pwdLastSet", CLng(0)
                objuser.SetInfo
            End if
            next
        Next
        
        WScript.Echo intCounter & " Users change pwd next logon. Value " _
        & intAccValue
        WScript.Quit
    But I'm still Getting an Error message:

    Line: 34
    char: 9
    Error: 0x80005000
    Code: 80005000
    Source: (null)

    What do to?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.