teachermc
Goto Top

Hinzufügen von Usern mit einer EXCEL Liste und WSH

Im NT-Resource Kit ist ein VBS Programm "Adduseres", womit man über eine EXCEL Liste Einträge in das Acitive Directory vornehmen kann.Ich möchte dieses Tool verwenden und auf meinem Server einrichten. Bräuchte dringend Hilfe!!

Hierzu muss man eigentlich nur die Root Adresse für das LDAP Protokoll sowie die OU in der Beispiel EXCEL Tabelle ändern.
Und genau das ist mein Problem.Was muss ich in der EXCEL Tabelle in der Zelle für die Root genau eintragen ??

In der Beispiel EXCEL Tabelle wird für die Root angegeben:
DC=ArcadiaBay,DC=Com,O=Internet

Ich habe mit die Admin Tool von der Server CD installiert und mit dem Tool LDP nachgeschaut, wie meine Root dargestellt wird.Und die sieht wie folgt aus:
ldap:server-203.R203.hgs.kn.bw.schule.de/DC=R203,DC=hgs,...

Hieraus habe ich die Angaben für DC=... genommen
Aber was bedeutet O=...? Steht das für Object?

Wie finde ich heraus, was ich hier eintragen muss bei meinem Server?

Ich habe an dieser Stelle meinen Rechnernamen angegeben und bekomme eine Fehlermeldung...


Hier ist nochmal das VBS Script:


'
' ------------------------------------------------------------------------
' Copyright (C) 1996 Microsoft Corporation
'
' You have a royalty-free right to use, modify, reproduce and distribute
' the Sample Application Files (and/or any modified version) in any way
' you find useful, provided that you agree that Microsoft has no warranty,
' obligations or liability for any Sample Application Files.
' ------------------------------------------------------------------------
'
'This script is adds users from the Windows NT DS
'via ADSI. The script reads an EXCEL spreadsheet that contains a page
'of users to add.
'
'The sample uses the directory root "LDAP:
DC=ArcadiaBay,DC=Com,O=Internet"
'Change the directory path in the EXCEL spreadsheet to match your DS
'before running this sample.
'
'
'
'To add users, run ADDUSERS.VBS with %windir%\"Your Samples Directory Here"\AddUsers.XLS.
'To Delete users, run DELUSERS.VBS with %windir%\"Your Samples Directory Here"\DelUsers.XLS.


Dim oXL
Dim u
Dim c
Dim root
Dim ou
Dim TextXL
Dim CRLF
dim oArgs


'Get the command line args
set oArgs=wscript.arguments

CRLF = Chr(13) & Chr(10)

'If no command line arguments provided, prompt for file containing users to add/delete
If oArgs.Count = 0 Then
TextXL = InputBox("This scripts reads an Excel spreadsheet and adds" & _
"users from the Windows NT DS via ADSI." & CRLF & CRLF & _
"Before starting, change the DS root in the EXCEL spreadsheet to match " & _
"your DS." & CRLF & CRLF & _
"Type in the path of a file containing users to add or delete" & CRLF & CRLF & _
"Sample Add User file: ADDUSERS.XLS" & CRLF & _
"Sample Delete User file: DELUSERS.XLS" & CRLF)
'Else file containing users is the first argument
Else
TextXL = oArgs.item(0)
End If

If TextXL = "" Then
WScript.Echo "No input file provided. Stopping the script now."
WScript.Quit(1)
End If

'We will use ou to control loop, so set initial value to null
ou = ""

'Start EXCEL and display it to the user
Set oXL = WScript.CreateObject("EXCEL.application")
oXL.Visible = True

'Open the workbook passed in the command line
oXL.workbooks.open TextXL

'Activate the Add page
oXL.sheets("Add").Activate

'Put the cursor in the starting cell and read the DS root
oXL.ActiveSheet.range("A2").Activate ' this cell has the DS root in it

'Show it to the user
'WScript.Echo oXL.activecell.Value

'This is the starting point in the ds
root = oXL.activecell.Value

'Step to the next row
oXL.activecell.offset(1, 0).Activate

'Until we run out of rows
Do While oXL.activecell.Value <> ""

'if the requested OU is a new one...
If oXL.activecell.Value <> ou Then
'Pick up the OU name...
ou = oXL.activecell.Value

'Compose the ADSI path...
s = "LDAP://" + ou+"," + root

'Show it to the user...
WScript.Echo s

'And get the object
Set c = GetObject(s)
End If

'Compose the user common name name from first and last names...
uname = "CN=" + oXL.activecell.offset(0, 1).Value + " " + oXL.activecell.offset(0, 2).Value

'Create the new user object...
Set u = c.Create("user", uname)

'Set the properties of the new user
u.Put "givenName", oXL.activecell.offset(0, 1).Value 'givenName
u.Put "sn", oXL.activecell.offset(0, 2).Value 'sn
u.Put "mail", oXL.activecell.offset(0, 3).Value 'Email
u.Put "sAMAccountName", oXL.activecell.offset(0, 4).Value 'Sam Acct
u.Put "telephoneNumber", oXL.activecell.offset(0, 5).Value 'Phone

'Enable the account, must change pw @ logon
u.Put "userAccountControl",16

'...and update the DS
u.SetInfo

'Done with this object, discard it
Set u = Nothing

'Step to the next user...
oXL.activecell.offset(1, 0).Activate 'Next row
Loop


'Done. close excel spreadsheet
oXL.application.quit

Content-Key: 244

Url: https://administrator.de/contentid/244

Ausgedruckt am: 29.03.2024 um 15:03 Uhr

Mitglied: ggedv
ggedv 11.03.2002 um 08:51:30 Uhr
Goto Top
Der LDAP-Pfad müsste eigentlich so aussehen:
für z. B. eine OU "Test" in meiner Domäne wäre das z. B.
OU=Test,DC=NThelp,DC=de
Davor kommen entsprechende Objekte bzw. Attribute.

Wenn Du die Benutzer in einer bestimmten OU anlegen willst, dann erstelle dort ein Beispiel-Benutzerkonto mit allen Attributen und lese ihn dann mit dem Programm, der mitgelifert wird: csvde.exe oder ldif.exe aus. Damit bekommst Du die Attribute (Spaltennamen) und Pfade.

Wenn Deine User nicht unbedingt in einer Excel-Tabelle liegen müssen, dann speichere sie als CSV-Datei ab und imporiere in Active Directory mit dem o. g. Programm csvde.exe mit den Schaltern: /i /f:[Dateiname.csv] (Schaue Die auch die Hilfe an).

Dieses Programm kann nur Objekte in AD importieren. ldifde.exe kann dagegen auch andere Aktionen wie z. B. Ändern, Löschen, etc. die .ldif-Dateien haben aber einen "etwas" anderen Format als .csv-Dateien.

Ich hoffe ich konnte helfen.

Gregor Gabor
Gregor@NThelp.de