[VBscript] data toevoegen aan bestaand object

Pagina: 1
Acties:
  • 75 views

Acties:
  • 0 Henk 'm!

  • DarkSide
  • Registratie: Oktober 2000
  • Laatst online: 20-09 20:57

DarkSide

theres no place like ::1

Topicstarter
Ik ben me aan het inlezen in het maken van vbscripts. Ik heb een scipt gemaakt wat gebruikers aanmaakt in AD. De info komt uit een excel bestand. Dit werkt ook prima. Echter als ik een veld in excel verander (bv het telefoonnummer) dan wordt dit niet gewijzigd in AD. Ik krijg ook een melding dat het object al bestaat als ik het script nogmaals uitvoer. Dit heb ik omzijld door on error resume next te gebruiken.

Maar ik zou graag data in een bestaand object willen wijzigen/toevoegen.

Dit is wat ik tot nu toe gemaakt hebt.
VBScript:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Option Explicit
Dim objRootLDAP, objContainer, objUser, objShell
Dim objExcel, objSpread, intRow
Dim strUser, strOU, strSheet
Dim strCN, strSam, strFirst, strLast, strPWD, strDEScription, strUPN, strDEPartment, strhomp, strMob, strPhon, strPost

' -------------------------------------------------------------'
' Important change OU= and strSheet to reflect your domain
' -------------------------------------------------------------'

strOU = "OU=test ," ' Note the comma
strSheet = "c:\test2.xls"

' Bind to Active Directory, Users container.
Set objRootLDAP = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://" & strOU & _
objRootLDAP.Get("defaultNamingContext")) 

' Open the Excel spreadsheet
Set objExcel = CreateObject("Excel.Application")
Set objSpread = objExcel.Workbooks.Open(strSheet)
intRow = 3 'Row 1 often contains headings

' Here is the 'DO...Loop' that cycles through the cells
' Note intRow, x must correspond to the column in strSheet
Do Until objExcel.Cells(intRow,1).Value = ""
   strSam = Trim(objExcel.Cells(intRow, 1).Value)
   strCN = Trim(objExcel.Cells(intRow, 2).Value) 
   strFirst = Trim(objExcel.Cells(intRow, 3).Value)
   strLast = Trim(objExcel.Cells(intRow, 4).Value)
   strPWD = Trim(objExcel.Cells(intRow, 5).Value)
   strUPN = Trim(objExcel.Cells(intRow, 7).Value)
   strDEScription = Trim(objexcel.Cells(intRow, 6).Value)
   strDEPartment = Trim(objExcel.Cells(intRow, 8).Value)
   strhomp = Trim(objExcel.Cells(intRow, 9).Value)
   strMob = Trim(objExcel.Cells(intRow, 10).value)
   StrPhon = Trim(objExcel.Cells(intRow, 11).Value)
   StrPost = Trim(objExcel.Cells(intRow, 12).Value)


   ' Build the actual User from data in strSheet.
   Set objUser = objContainer.Create("User", "cn=" & strCN)
   objUser.sAMAccountName = strSam
   objUser.givenName = strFirst
   objUser.sn = strLast
   objUser.description = strDEScription
   objUser.userPrincipalName = strUPN
   objUser.department = strDEPartment
   objUser.homephone = strHomp
   objUser.mobile = strMob
   objUser.telephonenumber = strPhon
   objUser.postalcode = strPost
   On Error Resume Next
   objUser.SetInfo


   ' Separate section to enable account with its password
   objUser.userAccountControl = 512
   objUser.pwdLastSet = 0
   objUser.SetPassword strPWD
   objUser.SetInfo

intRow = intRow + 1
Loop
objExcel.Quit 


Wscript.Echo "Success, Check Active Directory Users and Computers - Remember F5"


Kan iemand een tip geven?

There are 10 kinds of people in this world..... Those who know binary. And those who don't.


Acties:
  • 0 Henk 'm!

  • RobIII
  • Registratie: December 2001
  • Niet online

RobIII

Admin Devschuur®

^ Romeinse Ⅲ ja!

(overleden)
Voor support op "geleende scripts" kun je aankloppen bij de auteur ;)

Overigens is een on error resume next wel 't laatste wat je wil als je aan 't debuggen bent.

[ Voor 44% gewijzigd door RobIII op 29-04-2009 16:42 ]

There are only two hard problems in distributed systems: 2. Exactly-once delivery 1. Guaranteed order of messages 2. Exactly-once delivery.

Je eigen tweaker.me redirect

Over mij


Dit topic is gesloten.