Jump to content

Import CSV file to Add users in AD


Recommended Posts

Hello,

I want to create a script that can read a csv file and use this data to create users in Active Directory with the tool dsadd.

CSV file looks like this :

ABeerens;Ans Beerens;Ans;Beerens;Welkom01

ABos;Annemiek Bos;Annemiek;Bos;Welkom01

ABraat;Ans Braat;Ans;Braat;Welkom01

Is it possible to create variables from the different pieces in the file.

For example

$Var1=ABeerens

$Var2=Ans Beerens

$Var3=Ans

$Var4=Beerens

$Var5=Welkom01

dsadd $Var1,Var2 ....

Loop

And so on.

I want to create a loop until the end of the file is reached.

Link to comment
Share on other sites

You could read the file to an array (_FileReadToArray)

then loop through that array, splitting each record into smaller arrays with StringSplit

In your example, you would have an array set up like

_FileReadToArray("Whatever\file.csv",$csv)

;0=3

;1=ABeerens;Ans Beerens;Ans;Beerens;Welkom01

;2=ABos;Annemiek Bos;Annemiek;Bos;Welkom01

;3=ABraat;Ans Braat;Ans;Braat;Welkom01

For $i=1 to Ubound($csv)-1

$record=StringSplit($csv[$i],";")

;0=5

;1=ABeerens

;2=Ans Beerens

;3=Ans

;4=Beerens

;5=Welkom01

;Then you can dsadd $csv[1], $csv[2]

Next

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

May I suggest to use the Active Directory UDF - function _AD_CreateUser - to add users? You can create a user in a different OU in one go and have better error handling.

You can find the download link in my signature below.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...