#203109 - 2011-09-20 01:12 PM
User import from CSV
|
Beuz1
Fresh Scripter
Registered: 2011-09-19
Posts: 8
Loc: Groningen, The Netherlands
|
Hi,
I want to add users to my win2003 DC from a CSV using kixtart. Can't seem to find this information on the internet. I found some functions to read a CSV file but don't know how to get te user information from the CSV and add this users to a OU. The OU and username is given in the CSV.
Thanks
|
|
Top
|
|
|
|
#203111 - 2011-09-20 01:25 PM
Re: User import from CSV
[Re: Beuz1]
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11629
Loc: CA
|
Hello Beuz1 and welcome to the board.
I don't think there is any pre-written code to do exactly what you're asking.
You would probably need to hand code it, but there are hundreds of UDF scripts that can help you to achieve your goals.
http://www.kixtart.org/udf/
Can you post some example data of your CSV (you can use dummy data) so that we can see what you've got so far and what you're trying to do.
|
|
Top
|
|
|
|
#203113 - 2011-09-20 02:04 PM
Re: User import from CSV
[Re: Lonkero]
|
Beuz1
Fresh Scripter
Registered: 2011-09-19
Posts: 8
Loc: Groningen, The Netherlands
|
Thanks for the quick reply's! My CSV looks like this: UserID First name Class (OU) xxxxxx (numeric) John Doe MB109
If a person doesn't have a class they will be added to the OU ExStudents.
|
|
Top
|
|
|
|
#203115 - 2011-09-20 03:49 PM
Re: User import from CSV
[Re: Beuz1]
|
Beuz1
Fresh Scripter
Registered: 2011-09-19
Posts: 8
Loc: Groningen, The Netherlands
|
This is my code so far:
Break on
$filename = "test1.csv"
If Open(1,$filename) = 0
$line = ReadLine(1)
While @ERROR = 0
$array = Split($line,",")
?
For Each $field In $array
? $field
Next
$line = ReadLine(1)
Loop
$= Close(1)
EndIf
Exit 1
It just reads my csv and shows it on the screen. But I don't know how to use this values to create users.
|
|
Top
|
|
|
|
#203121 - 2011-09-21 08:37 AM
Re: User import from CSV
[Re: Allen]
|
Beuz1
Fresh Scripter
Registered: 2011-09-19
Posts: 8
Loc: Groningen, The Netherlands
|
Thanks again! But I see a lot of code there and I'm pretty new with Kix. The only thing I need is to put a specific line of a CSV into a variable to create the user with that 4 variables (UserID, First name, Last name and class). When I have that variables from the CSV it can't be difficult to do the rest.
|
|
Top
|
|
|
|
#203219 - 2011-10-10 02:57 PM
Re: User import from CSV
[Re: Glenn Barnas]
|
Beuz1
Fresh Scripter
Registered: 2011-09-19
Posts: 8
Loc: Groningen, The Netherlands
|
Result:
Break on
$filename = "test1.csv"
If Open(1,$filename) = 0
$line = ReadLine(1)
While @ERROR = 0
$array = Split($line,",")
?
? "De volgende gebruiker wordt toegevoegd:"
? $array[0] + " uit lokaal " + $array[4] + "."
CreateUserAccount("TestServer.local",
"cn= Users",
$array[0],
$array[1],
$array[2],
"Dit is een user die is aangemaakt door het script van Jeroen Beuzenberg",
$array[4],
"http://www.jeroenbeuzenberg.test.nl",
$array[1])
Function CreateUserAccount($Domain,
$ContainerDN,
$Account,
$FirstName,
$LastName,
optional $Description,
optional $lokaal,
optional $WebPage,
$password,
optional $userPrincipalName )
Dim $aDom, $part, $sDNdom, $LDAPpath, $oContainer, $oUser
if VarTypeName($userPrincipalName) = "Empty"
$userPrincipalName = $Account + "@@" + $Domain
endif
$aDom = split($Domain,".")
for each $part in $aDom
$sDNdom = "" + $sDNdom + ",dc=" + $part
next
$LDAPpath = "LDAP://" + $Domain + "/" + $ContainerDN + $sDNdom
;? $LDAPpath
$oContainer = GetObject($LDAPpath)
if @error
? "GetObject Error: " + @error + " " + @Serror
endif
$oUser = $oContainer.Create("User", "cn=" + $Account)
if @error
? "Create Error: " + @error + " " + @Serror
endif
$oUser.Put("sAMAccountName", $Account)
$oUser.Put("givenName", $FirstName)
$oUser.Put("sn", $LastName)
$oUser.Put("displayName",$LastName + iif($LastName, ", ","") +
$FirstName + iif($MiddleInitial, " ", "") +
$MiddleInitial)
$oUser.Put("description", $Description)
$oUser.Put("physicalDeliveryOfficeName",$lokaal)
$oUser.Put("wWWHomePage",$WebPage)
$oUser.Put("userPrincipalName", $userPrincipalName)
$oUser.SetInfo
$oUser.AccountDisabled = 0
$oUser.SetPassword($password)
$oUser.SetInfo
$CreateUserAccount = @ERROR
if $CreateUserAccount
? "SetInfo Error: "" Deze gebruiker bestaat al! "
? "De gebruiker [" + $array[0] + "] die u probeerde toe te voegen is niet gewijzigd."
? "Foutcode: "
endif
Endfunction
$line = ReadLine(1)
Loop
$= Close(1)
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 394 anonymous users online.
|
|
|