Creating User Accounts in a subOU with VBScript

Okay, this is a stupid question. I have this VBScript to create user accounts and in it is a line that reads "strOU = "OU=Disabled User Accounts" ' Note the comma". I need to edit this line so that I can have the accounts created in a subOU. The way it's written now it will only find a top-level OU. For example, let's say I have an OU structure such that I have an OU named OU3 that's in OU2 which is in OU1 (OU1 is a top-level OU). I need for the accounts to be created in OU3. How do I edit that one line so that the accounts are in OU3? I thought I would just list the OUs in reverse order like this:

strOU = "OU=OU3,OU=OU2,OU=OU1"

I thought that's how you would edit that line but it's not working. Please help. Thanks.

Option Explicit
Dim objRootLDAP, objContainer, objUser, objShell
Dim objExcel, objSpread, intRow
Dim strUser, strOU, strSheet, strUPN, strDispName
Dim strCN, strSam, strFirst, strLast, strPWD, strDesc
strOU = "OU=UserAccounts" ' Note the comma
strSheet = "c:\useraccounts.xls"
' Bind to Active Directory, Users container.
Set objRootLDAP = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://" & strOU & _
' Open the Excel spreadsheet
Set objExcel = CreateObject("Excel.Application")
Set objSpread = objExcel.Workbooks.Open(strSheet)
intRow = 3 'Row 1 often contains headings
' Here is the 'DO...Loop' that cycles through the cells
' Note intRow, x must correspond to the column in strSheet
' Trim function eliminates blank spaces
Do Until objExcel.Cells(intRow,1).Value = ""
   strSam = Trim(objExcel.Cells(intRow, 1).Value)
   strCN = Trim(objExcel.Cells(intRow, 2).Value) 
   strLast = Trim(objExcel.Cells(intRow, 3).Value)
   strFirst = Trim(objExcel.Cells(intRow, 4).Value)
   strPWD = Trim(objExcel.Cells(intRow, 5).Value)
   strUPN = Trim(objExcel.Cells(intRow, 6).Value)
   strDispName = Trim(objExcel.Cells(intRow, 7).Value)
   strDesc = Trim(objExcel.Cells(intRow, 8).Value)
   ' Build the actual User from data in strSheet.
   Set objUser = objContainer.Create("User", "cn=" & strCN)
   objUser.sAMAccountName = strSam
   objUser.givenName = strFirst = strLast
   objUser.userPrincipalName = strUPN
   objUser.displayName = strDispName
   objUser.description = strDesc
   ' Separate section to enable account with its password
   objUser.userAccountControl = 512
   objUser.pwdLastSet = 0
   objUser.SetPassword strPWD
intRow = intRow + 1

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try using this ...
strOU = "OU=OU3,OU=OU2,OU=OU1,"
Make sure there is a comma at the end of the string.

I think that the current script is merging the strings so that it looks like this;
As you can see, there whould be a comma between the OU1 and DC=

Give that a try and let me know if that works for you.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mcpp661Author Commented:
Thanks man, I know better than that. It's always something small that ends up missing.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.