locked
Import users to ad from csv file RRS feed

  • Question

  • hi there ,

    i need help with this. i have a lot of csv file with users that needs to be created on AD. Not sure what the commands will be.

    the csv file format is as follows

    user name, firstname, lastname, password , company,ou

     

    What do i use to import this info. Have treid csvde but i dont know how.

    Any help would be greatly appreciated

    thanks

    Chris van Dyk

     

    Tuesday, August 30, 2011 6:32 AM

Answers

  • Hi Everyone,

     

    thanks for you response!

    I got the users created with a bat file and dsadd command.

    dsadd user cn=,ou=userou,ou=Users,dc=domain,dc=co,dc=za -upn @domain.co.za -display "" -pwd  -mustchpwd no -fn "" -ln "" -company ""

     

    We created a excel sheet the auto fills in all the fileds.  all i did wat to copy and paste all the user names , surenames and passwords . save the result in to a bat file and run it on the server.

     

    Let me know it you guys would like the excel sheet.

     

    Thanks

     

    Chris van Dyk

    • Marked as answer by Cvandyk Tuesday, August 30, 2011 11:29 AM
    Tuesday, August 30, 2011 11:29 AM

All replies

  • Have you tried to use CSVDE on a DC or workstation with Administrative Tools / RSAT installed with these switches ?

    csvde -i -f <filename.csv>

    -i means import mode

    -f means read from file specified after a switch

    One important information. CSVDE cannot alter/modify existing account. So, all of them cannot be present withijn AD database. CSVDE also cannot set up initial password for users. You have to do after import by yourself (i.e. using DC Tools to set initial password)


    Regards, Krzysztof Visit my blog at http://kpytko.wordpress.com
    Tuesday, August 30, 2011 6:47 AM
  • You need some script for adding user from csv ,and it's easy you can add every parameter you want.

     

    So hire is example and it's work:

    It put in DGDO Organization unit you need to change that and every parameter you don't like you need just to delete from two place in script or put some new parameter

    https://skydrive.live.com/?cid=660f69119a9a474a&sc=documents&uc=2&id=660F69119A9A474A%21209#

     

    And run script from power shell because is .ps1 file

    Tuesday, August 30, 2011 7:03 AM
  • I have played some time with various tools and find, that the simplest way is visual basic script, because of plenty of scripts that solve partial tasks and because of creating visual basic script has been fast procedure to set the working script. Today I would prefere PS, but if you need fast solution now, then adapting the following script may be the fastest way:

     

    '****************************************************************

      OPTION EXPLICIT

    '****************************************************************

    '  Definition of variables

    '****************************************************************

    Dim strFileName, strNextLine

    Dim objFSO, objTextFile, objScriptExec, objShell

    Dim arrUserLine

    Dim strSamID,strFn,strLn,strPWD,strEmplID

    Dim strGrpID,strCategory,strComeIn,strAccExpir

    Dim strSuffix0,strSuffix, strDN, strFunction,strExProfile

    Dim objWMI,objUsers,strComputer,strCount,strCount1,strExpDate

    Dim strUsrGrp,strEndUser

    '*****************************************************************

    '  Definice konstant

    '*****************************************************************

    Const ForReading = 1                        ' For reading only

    strFileName = "g:\in\nt336.txt"             ' Imput data file

    strSuffix0 = "dc=nt,dc=fel"                 ' Domain

    Const Sleep_a_bit = 35                      ' Sleeping interval 

    strComputer = "."                           ' "." means this server

    strCount = 0

    strCount1 = 0

    strExpDate = "09/30/2015"

    strEndUser = "zzzzzzzz"

    '******************************************************************

    '  Definition of object file

    '******************************************************************

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Set objTextFile = objFSO.OpenTextFile(strFileName ,ForReading)

    '******************************************************************

    '  Definition of shellu

    '******************************************************************

    Set objShell = CreateObject("Wscript.Shell")

    '******************************************************************

    '  Do cycle for reading input file

    '******************************************************************

    Do Until objTextFile.AtEndOfStream

       strNextLine = objTextFile.Readline

       arrUserLine = Split(strNextLine,",")

       strExProfile = 0

       strSamID = arrUserLine(0)          ' SamAccountName (required) 

       strLn = arrUserLine(1)             ' Surname

       strFn = arrUserLine(2)             ' Given Name

       strPWD = arrUserLine(3)            ' Heslo

       strEmplID = arrUserLine(4)         ' User ID 4 UNIX

       strGrpID = arrUserLine(5)          ' Group ID 4 UNIX

       strCategory = arrUserLine(6)       ' Category (student, teacher,...)

       strComeIn = arrUserLine(7)         ' Date of input

    '   strAccExpir = arrUserLine(8)      ' Date of expiration

       strAccExpir = strExpDate

    ' ******************************************************************

    ' Is it the ending user (special name defined at the beginning)

    ' ******************************************************************

    If strSamID = strEndUser Then

    '        Wscript.Echo "KONEC"

            Exit Do

        End If

    '*******************************************************************

       strExProfile = 1

    '  strExProfile = 0 ' No profile created on server

    '*******************************************************************

       SELECT CASE strCategory

              CASE "zam" 

              strSuffix = "ou=employees,ou=people," & strSuffix0

              strUsrGrp = "cn=ggEmployees,ou=Groups," & strSuffix0

              CASE "stud" 

              strSuffix = "ou=students,ou=people," & strSuffix0

              strUsrGrp = "cn=ggStudents,ou=Groups," & strSuffix0

              CASE "other" 

              strSuffix = "ou=other,ou=people," & strSuffix0

              strUsrGrp = "cn=ggOther,ou=Groups," & strSuffix0

              CASE "dokt" 

              strSuffix = "ou=phd-students,ou=people," & strSuffix0

              strUsrGrp = "cn=ggPHD,ou=Groups," & strSuffix0

              CASE "u3v" 

              strSuffix = "ou=u3v,ou=people," & strSuffix0

              strUsrGrp = "cn=ggU3V,ou=Groups," & strSuffix0

              CASE ELSE

              strSuffix = "ou=misc,ou=people," & strSuffix0

              strUsrGrp = "cn=ggMisc,ou=Groups," & strSuffix0

       END SELECT

    '

    '******************************************************************************

    '  Does the user exists?

    '******************************************************************************

    Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\directory\LDAP")

    Set objUsers = _

        objWMI.ExecQuery("SELECT * FROM ds_user where ds_sAMAccountName = '"& strSamID &"' ")

    if objUsers.Count = 0 then

    '   Wscript.Echo "No matching objects found"

       Call AddUser(strSamID,strSuffix,strFn,strLn,strPWD,strAccExpir,strExProfile)

       Call AddUsr2Grp(strSamID,strFn,strLn,strSuffix,strUsrGrp)

       strcount1 = strCount1 + 1

    else

    '    Wscript.Echo "User is IN"

        strcount = strCount + 1

    end if

    Set objWMI = Nothing

    Set objUsers = Nothing

         Wscript.Sleep Sleep_a_bit

    LOOP

    '     Wscript.Echo strCount

    '     Wscript.Echo strCount1

    '*****************************************************************************

    ' Subroutine

    '*****************************************************************************

    Sub AddUser(strSamID,strSuffix,strFn,strLn,strPWD,strAccExpir,strExProfile)

    Const vbMinimizedNoFocus = 6

    '**********************************************************************

    ' Definice konstant pro subroutinu

    '**********************************************************************

    Const UF_SCRIPT = &H1

    Const UF_ACCOUNTDISABLE = &H2

    Const UF_HOMEDIR_REQUIRED = &H8

    Const UF_LOCKOUT = &H10

    Const UF_PASSWD_NOTREQD = &H20

    Const UF_PASSWORD_CANT_CHANGE = &H40

    Const UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED = &H80

    Const UF_DONT_EXPIRE_PASSWD = &H10000

    Const UF_MNS_LOGON_ACCOUNT = &H20000

    Const UF_SMARTCARD_REQUIRED = &H40000

    Const UF_TRUSTED_FOR_DELEGATION = &H80000

    Const UF_NOT_DELEGATED = &H100000

    Const ADS_PROPERTY_UPDATE = 2

    Dim objDomain, objUser, fso, intUserFlags, intNewUserFlags

    Dim fldUserHomedir, wshShell

    'Dim strSamID,strSuffix,strFn,strLn,strPWD,strAccExpir

     

    Set objDomain = GetObject("LDAP://" & strSuffix)

    Set objUser = objDomain.Create("user","cn=" & strSamID)

    objUser.Put "sAMAccountName", strSamID

    objUser.Put "userPrincipalName", strSamID & "@nt.fel"

    '**********************************************************************

    '  Set information

    '**********************************************************************

    objUser.SetInfo

    objUser.GetInfo

    '**********************************************************************200

    '  Set of variables

    '**********************************************************************

    objUser.AccountDisabled = False

    objUser.AccountExpirationDate = strAccExpir

    'objUser.Description = "My description goes here!"

    objUser.IsAccountLocked = False

    'objUser.LoginScript = "login.vbs”

    IF CBool(strExProfile) THEN _

             objUser.Profile = "\\sa1.nt.fel\profile$\"& strSamID

    'objUser.PasswordRequired = True

    objUser.FirstName = strFn

    objUser.LastName = strLn

    objUser.DisplayName = strLn & " " & strFN

    '**********************************************************************

    '  Home directory mapping

    '**********************************************************************

    objUser.HomeDirectory = "\\sa1.nt.fel\home\" & strSamID

    objUser.Put "homeDrive", "H:"

    '**********************************************************************

    '  Set information

    '**********************************************************************

    objUser.SetInfo

    objUser.GetInfo

    '**********************************************************************

    '  Password never expired

    '**********************************************************************

    intUserFlags = objUser.Get("userAccountControl")

    intNewUserFlags = intUserFlags Or UF_DONT_EXPIRE_PASSWD

    intNewUserFlags = intNewUserFlags Or UF_PASSWORD_CANT_CHANGE

    objUser.Put "userAccountControl", intNewUserFlags

    objUser.SetInfo

    '**********************************************************************

    'Create the home directory

    '**********************************************************************

    Set fso = CreateObject("Scripting.FileSystemObject")

    If Not fso.FolderExists("e:\home\" & strSamID ) Then

            Set fldUserHomedir = fso.CreateFolder("e:\home\" _

            & strSamID)

    End If

    '**********************************************************************

    '  FULL in home directory

    '**********************************************************************

    Set wshShell = WScript.CreateObject("Wscript.Shell")

    wshShell.Run "cacls.exe e:\home\" & strSamID & " /E /T /G " _

               & strSamId & ":F", vbMinimizedNoFocus, True

    '**********************************************************************

    ' Set password

    '**********************************************************************

    objUser.SetPassword strPWD

    End Sub

    '**********************************************************************

    '  Subroutine -  Add user into group

    '**********************************************************************

    Sub AddUsr2Grp(strSamID,strFn,strLn,strSuffix,strUsrGrp)

    Dim objGroup,strTest

    Const ADS_PROPERTY_APPEND = 3

    Set objGroup = GetObject("LDAP://" & strUsrGrp)

    objGroup.PutEx ADS_PROPERTY_APPEND, "member", _

                Array("CN=" & strSamID & "," & strSuffix)

    objGroup.SetInfo

    End Sub

     

    Tuesday, August 30, 2011 7:13 AM
  • Hi Everyone,

     

    thanks for you response!

    I got the users created with a bat file and dsadd command.

    dsadd user cn=,ou=userou,ou=Users,dc=domain,dc=co,dc=za -upn @domain.co.za -display "" -pwd  -mustchpwd no -fn "" -ln "" -company ""

     

    We created a excel sheet the auto fills in all the fileds.  all i did wat to copy and paste all the user names , surenames and passwords . save the result in to a bat file and run it on the server.

     

    Let me know it you guys would like the excel sheet.

     

    Thanks

     

    Chris van Dyk

    • Marked as answer by Cvandyk Tuesday, August 30, 2011 11:29 AM
    Tuesday, August 30, 2011 11:29 AM