Login | |
|
 |
Need help with script!!! - 12/19/2007 3:36:42 AM
|
|
 |
|
| |
jbrandt
Posts: 5
Score: 0
Joined: 12/19/2007
Status: offline
|
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 & ">"
|
|
| |
|
|
|
 |
RE: Need help with script!!! - 12/19/2007 3:50:18 AM
|
|
 |
|
| |
ebgreen
Posts: 5250
Score: 31
Joined: 7/12/2005
Status: offline
|
In that case, I would just iterate through all the rows in the excel file and for each row, get the AD object for the user name, then set the field for that object.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Need help with script!!! - 12/19/2007 3:54:46 AM
|
|
 |
|
| |
ebgreen
Posts: 5250
Score: 31
Joined: 7/12/2005
Status: offline
|
Well, right here: Do Until objRecordset.EOF Wscript.Echo objRecordset.Fields.Item("Name"), _ objRecordset.Fields.Item("ID") objRecordset.MoveNext Loop You are already iterating through every row in the spreadsheet.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Need help with script!!! - 12/19/2007 4:14:44 AM
|
|
 |
|
| |
ebgreen
Posts: 5250
Score: 31
Joined: 7/12/2005
Status: offline
|
You need to go back to wherever you copied that code from. You missed some. This code: ' 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$] Sets up some variables that you will use to connect to the Excel spreadsheet and query it as if it were a database. You never connect and execute the query.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
|
|