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)