General discussion

Locked

Required CSV files.

By saidulu.p ·
Hello all
i have a scenario where in i have to create 100 users in Active Direcotry.
i heard that we can create users in bulk using csv files. As well we can edit user attributes.but i dont konw how to create csv files.


My Requirement is
1. have to create 100 users in AD environment
2. have to edit attributes for 150 users

can any one provide me the work around for this.

Thanks in advance.

This conversation is currently closed to new comments.

6 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

How many times are you going to post

by Wizard-09 In reply to Required CSV files.

I answered this question 2 times today for you try looking at the reply I sent you.

Collapse -

How do we make that CSV file and what is the CSV File format.

by saidulu.p In reply to How many times are you go ...

Below is the VBscript for creating users from csv files.

If u examine the below command, we are giving input file as csv file which contains all the details like first name, last name...etc.
How do we make that CSV file and what is the CSV File format.

' Input file location
sCSVFileLocation = "C:\Scripts\" 'KEEP TRAILING SLASH!

' Full path to input file
sCSVFile = sCSVFileLocation&"Book2.csv"


' ---------------------------------------------------
' Script: createusersfromcsv.vbs
' Author: Scott Lowe
' Input: CSV file with layout logonname,firstname,lastname,password
' Date: December 21, 2005
' Change log:
' no changes
'----------------------------------------------------

Option Explicit

Dim sCSVFileLocation
Dim sCSVFile
Dim oConnection
Dim oRecordSet
Dim oNewUser

' Variables needed for LDAP connection
Dim oRootLDAP
Dim oContainer

' Holding variables for information import from CSV file
Dim sLogon
Dim sFirstName
Dim sLastName
Dim sDisplayName
Dim sPassword
Dim nPwdLastSet
Dim nUserAccountControl ' Used to enable the account
Dim sDomain

' Modify this to match your company's AD domain
sDomain="example.com"

' Input file location
sCSVFileLocation = "C:\Scripts\" 'KEEP TRAILING SLASH!

' Full path to input file
sCSVFile = sCSVFileLocation&"Book2.csv"

' Commands used to open the CSV file and select all of the records
set oConnection = createobject("adodb.connection")
set oRecordSet = createobject("adodb.recordset")
oConnection.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & sCSVFileLocation & ";Extended Properties=""text;HDR=NO;FMT=Delimited"""
oRecordSet.open "SELECT * FROM " & sCSVFile ,oConnection

' Create a connection to the Active Directory Users container.
Set oRootLDAP = GetObject("LDAP://rootDSE")
Set oContainer = GetObject("LDAP://cn=Users," & _
oRootLDAP.Get("defaultNamingContext"))

' Allows processing to continue even if an error occurs (i.e. dup user)
' We put this below the CSV and AD information since processing can
' continue with a single bad record, but not if there is a problem with
' the CSV file or AD connection
on error resume next

do until oRecordSet.EOF ' Reads the values (cells) in the sInputFile file.

' --------- Start creating user account
' Read variable information from the CSV file
' and build everything needed to create the account
sLogon = oRecordSet.Fields.Item(0).value
sFirstName = oRecordSet.Fields.Item(1).value
sLastName = oRecordSet.Fields.Item(2).value
sDisplayName = sLastName&", "&sFirstName
sPassword = oRecordSet.Fields.Item(3).value

' Build the User account
Set oNewUser = oContainer.Create("User","cn="&sFirstName&" "&SLastName)

oNewUser.put "sAMAccountName",lcase(sLogon)
oNewUser.put "givenName",sFirstName
oNewUser.put "sn",sLastName
oNewUser.put "UserPrincipalName",lcase(SLogon)&"@"&sDomain
oNewUser.put "DisplayName",sDisplayName
oNewUser.put "name",lcase(sLogon)

' Write this information into Active Directory so we can
' modify the password and enable the user account
oNewUser.SetInfo

' Change the users password
oNewUser.SetPassword sPassword
oNewUser.Put "pwdLastSet", 0

' Enable the user account
oNewUser.Put "userAccountControl", 512
oNewUser.SetInfo

' Used only for debugging
'if err.number = -2147019886 then
' msgbox "User logon " & sLogon & "already exists"
'End If

' --------- End of user account creation

Collapse -

re: CSV files

by ThumbsUp2 In reply to Required CSV files.

Put your user information into a spreadsheet, then click the File... Save As... CSV.

Collapse -

what is the CSV File format.

by saidulu.p In reply to re: CSV files

what is the CSV File format.
what all are the columns we have to make in that file

thanks in advance,

Collapse -

Read the Script.....

by The 'G-Man.' In reply to what is the CSV File form ...

It Says.....

Start creating user account
' Read variable information from the CSV file

Collapse -

VB

by Wizard-09 In reply to Required CSV files.

And it's a VB script you need for this not CSV look in the question form were I asked your question 2 times today.

Back to Software Forum
6 total posts (Page 1 of 1)  

Related Discussions

Related Forums