Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Need help with script!!!

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,54560
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Need help with script!!!
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 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 & ">"
 
 
 
Post #: 1
 
 RE: Need help with script!!! - 12/19/2007 3:41:07 AM   
  ebgreen


Posts: 5250
Score: 31
Joined: 7/12/2005
Status: offline
First, why do you need to collec all the AD users? Do you do something special if there is an AD user that is not 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

(in reply to jbrandt)
 
 
Post #: 2
 
 RE: Need help with script!!! - 12/19/2007 3:43:29 AM   
  jbrandt

 

Posts: 5
Score: 0
Joined: 12/19/2007
Status: offline
No I don't need to collect all AD users, just the ones from the list that correspond to the spreadsheet with names and the id number.

(in reply to ebgreen)
 
 
Post #: 3
 
 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

(in reply to jbrandt)
 
 
Post #: 4
 
 RE: Need help with script!!! - 12/19/2007 3:52:33 AM   
  jbrandt

 

Posts: 5
Score: 0
Joined: 12/19/2007
Status: offline
Is that easy to do, I would use a For..next loop?  Not good with the coding yet!

(in reply to ebgreen)
 
 
Post #: 5
 
 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

(in reply to jbrandt)
 
 
Post #: 6
 
 RE: Need help with script!!! - 12/19/2007 3:57:32 AM   
  jbrandt

 

Posts: 5
Score: 0
Joined: 12/19/2007
Status: offline
So that part is ok.  How do I pull the names from AD that correspond to the .xls and update?   I assume I connect to excel, pull in the info, compare that data to AD, then update those records that correspond? I appreciate the help!

(in reply to ebgreen)
 
 
Post #: 7
 
 RE: Need help with script!!! - 12/19/2007 4:01:19 AM   
  ebgreen


Posts: 5250
Score: 31
Joined: 7/12/2005
Status: offline
You are already connecting to excel. I suggest your first step is to read the code that you have and understand what it does.

_____________________________

"... 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

(in reply to jbrandt)
 
 
Post #: 8
 
 RE: Need help with script!!! - 12/19/2007 4:08:41 AM   
  jbrandt

 

Posts: 5
Score: 0
Joined: 12/19/2007
Status: offline
If I understand correctly this code connect to excel, is the code correct?


' Connect to Excel Spreadsheet
strProvider = "Provider=Microsoft.Jet.OLEDB.4.0"
strExtend = "Extended Properties=Excel 8.0"
strFileName = "jenzabar_ids.xls"
strDataSource = "Data Source=" & strFileName
strQuery = "Select * from [Sheet1$]

The strQuery variable pulls in all the info from the spreadsheet.


The next part of the script reads the data into variables objRecordset.Fields.Item("Name") and objRecordset.Fields.Item("ID"):



Do Until objRecordset.EOF
Wscript.Echo objRecordset.Fields.Item("Name"), _
objRecordset.Fields.Item("ID")
objRecordset.MoveNext
Loop

Now I need to query AD where objRecordset.Fields.Item("Name") is equal to the username in AD and update those fields with objRecordset.Fields.Item.
I think I'm getting there.  Before I connect to AD do I need to close the connection to Excel or can I have them both open?

(in reply to ebgreen)
 
 
Post #: 9
 
 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

(in reply to jbrandt)
 
 
Post #: 10
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Need help with script!!! Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts