Re: Create OU and users with VBS and Excel
- From: "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 2 May 2007 11:18:46 -0500
The OU name should not have a trailing space (unless that is really the
case).
The attribute name for Display Name is displayName. You can use:
Dim strDisplay
strDisplay = Trim(objExcel.Cells(intRow, 5).Value)
objUser.displayName = strDisplay
It would be far easier to use columns of the spread*** to indicate which
OU each user should be created in, and what profile path to use. Instead of
"relations" in column 7, enter the name of the OU. Enter the profile path in
column 8. You can use spread*** formulas to create the values. In fact, an
Excel lookup function can probably be used. The spreadshet formula can
insert the sAMAccountName in the path. Then you can see for yourself if the
value is correct. Read the OU name from column 7 and bind to the container
object with that.
I would create the OU's ahead of time, either manually or in a separate
script. However, if you want to automate this all in one script, read the OU
names from row 2 (if I understand your format) and create the OU's first.
The syntax would be similar to:
intCol = 1
Do Until objExcel.Cells(2, intCol).Value = ""
strOU = Trim(objExcel.Cells(2, intCol)
strDNSDomain = objRootLDAP.Get("defaultNamingContext")
Set objDomain = GetObject("LDAP://" & strDNSDomain)
Set objOU = objDomain.Create("organizationalUnit", "ou=" & strOU)
objOU.SetInfo
intCol = intCol + 1
Loop
The attribute name for profile path is "profilePath".
To create the profile folders you can use the techniques demonstrated in
this sample VBScript program:
http://www.rlmueller.net/CreateUsers.htm
This program creates home folders, using a path read from a spread***. It
uses the FileSystemObject to first check if the folder exists. If it does
not, it creates it. It uses the Run method of the wshShell object to run the
cacls command to assign privileges for the folder to the new user object.
Similar code could work for your profile folders.
This should get you started. Of course, your final script should be tested
with a few test users.
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
<spam@xxxxxxxxxxxxxxx> wrote in message
news:1178091212.585361.304130@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm hoping to get some help from this group.
What I'm looking for is actually help to make a working VBS script,
that will create multiple OU's and users in a AD. Furthermore the
script also needs to make a profile folder on the hard drive.
I have made the spread*** and it contains the following:
Row1 : General info for the administrators
Row2: Our domain structure divided in columns. ( test ; test1 ;
local )
Row3: the starting folder structure on the hard drive, again divided
in columns. ( D: ; profiles ; )
Row 4:empty
Row5: Info about what has to be in the columns underneath.
Row6: first user.
The user info as divided in the columns like this:
Col A: SAMAccountName
Col B: Common Name
Col C: givenName
Col E: surname
Col F: displayName
Col G: Password
Col H: Relations
I have a script that can make the users, with a few exceptions.
_______________________________________________________________________________
Option Explicit
Dim objRootLDAP, objContainer, objUser, objShell
Dim objExcel, objSpread, intRow
Dim strUser, strOU, str***
Dim strCN, strSam, strFirst, strLast, strPWD
' -------------------------------------------------------------'
' Important change OU= and str*** to reflect your domain
' -------------------------------------------------------------'
strOU = "OU=test ," ' Note the comma
str*** = "C:\Script\users.xls"
' Bind to Active Directory, Users container.
Set objRootLDAP = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://" & strOU & _
objRootLDAP.Get("defaultNamingContext"))
' Open the Excel spread***
Set objExcel = CreateObject("Excel.Application")
Set objSpread = objExcel.Workbooks.Open(str***)
intRow = 7 'The First 6 Rows contains other INFO.
' Here is the 'DO...Loop' that cycles through the cells
' Note intRow, x must correspond to the column in str***
Do Until objExcel.Cells(intRow,1).Value = ""
strSam = Trim(objExcel.Cells(intRow, 1).Value)
strCN = Trim(objExcel.Cells(intRow, 2).Value)
strFirst = Trim(objExcel.Cells(intRow, 3).Value)
strLast = Trim(objExcel.Cells(intRow, 4).Value)
strPWD = Trim(objExcel.Cells(intRow, 6).Value)
' Build the actual User from data in str***.
Set objUser = objContainer.Create("User", "cn=" & strCN)
objUser.sAMAccountName = strSam
objUser.givenName = strFirst
objUser.sn = strLast
objUser.SetInfo
' Separate section to enable account with its password
objUser.userAccountControl = 512
objUser.pwdLastSet = 0
objUser.SetPassword strPWD
objUser.SetInfo
intRow = intRow + 1
Loop
objExcel.Quit
_______________________________________________________________________________
I need to get some help on changing the script, so it will set the
Display Name (Col F), set the profile path according to the path in
Row 3 and Col H (D:profiles/[COL H]/%USERNAME%) and make the folder in
D:profiles.
The script also needs to make a OU and place the right users in that
group depending on what there relations is.
I hope that someone can help me with this....
.
- Follow-Ups:
- Re: Create OU and users with VBS and Excel
- From: spam
- Re: Create OU and users with VBS and Excel
- References:
- Create OU and users with VBS and Excel
- From: spam
- Create OU and users with VBS and Excel
- Prev by Date: Last Login/Password Reset
- Next by Date: Re: Last Login/Password Reset
- Previous by thread: Create OU and users with VBS and Excel
- Next by thread: Re: Create OU and users with VBS and Excel
- Index(es):
Loading