Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with ADSI script

Status
Not open for further replies.
Sep 29, 2006
11
0
0
US
I'm creating a vb script to enter an employee id number into a created attribute id field on each user account in active directory. I have a spreadsheet with the login names and id numbers that need added. I need to collect all names from active directory and compare the names to the login names on the spreadsheet, if the names match, I will populate the employee id number with the id number from the spreadsheet for that person. I have attached what I've gotten so far, but I'm not sure how to compare AD to the spreadsheet. Please help! Thanks ahead of time!!!

Here is my code so far:
Option Explicit

Dim adoCommand, adoConnection, strBase, strFilter, strAttributes

Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strDN , strOUPath

Dim objUser

Dim strProvider, strDataSource, strExtend, strFileName

Const ADS_PROPERTY_CLEAR = 1

' Connect to Excel Spreadsheet

strProvider = "Provider=Microsoft.Jet.OLEDB.4.0"

strExtend = "Extended Properties=Excel 8.0"

strFileName = funfix("jenzabar_ids.xls")

strDataSource = "Data Source=" & strFileName

strQuery = "Select * from [Sheet1$]

Do Until objRecordset.EOF

Wscript.Echo objRecordset.Fields.Item("Name"), _

objRecordset.Fields.Item("ID")

objRecordset.MoveNext

Loop

' Setup ADO objects.

Set adoCommand = CreateObject("ADODB.Command")

Set adoConnection = CreateObject("ADODB.Connection")

adoConnection.Provider = "ADsDSOObject"

adoConnection.Open "Active Directory Provider"

adoCommand.ActiveConnection = adoConnection



' Search entire Active Directory domain.

Set objRootDSE = GetObject("LDAP://RootDSE")

strDNSDomain = objRootDSE.Get("defaultNamingContext")

strBase = "<LDAP://" & stroupath & strDNSDomain & ">"


 
I would change it so that you read your spreadsheet and add the login name and the id into a dictionary....i.e.

objDict.Add smith.john, 123
objDict.Add doe.jane, 453

Query AD for the users and use objDict.Exists to test and see if the login is in your dictionary...if so, then bind to the user object, update your field, and then move on to the next login.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
I would read the login name from your excel spreadsheet and then pass that to the function GetDistinguishedName from faq329-5688. That will allow you to bind to the user object in AD and set employeeID or employeeNumber, whichever property you are populating.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top