[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Edit script

Posted on 2006-03-29
3
Medium Priority
?
667 Views
Last Modified: 2012-08-14
Can someone please tell me how to edit this script so that it does not clear the workstation entries that are already enterered into the logon workstations field, and instead appends new entries? <Script Below>

Thanks,


Set filesys = CreateObject("Scripting.FileSystemObject")

Dim myfile
If filesys.FileExists("macs.csv") Then
   Set myfile = filesys.OpenTextFile("macs.csv")
Else
   MsgBox "Could not find file dbs.csv",0,"Error Finding File"
   Wscript.Quit
End If

Dim line, segs
Dim UserID, WorkStations
while not myfile.AtEndOfLine
    line = myfile.ReadLine
    segs = Split(line,",")

    UserID = segs(0)
    WorkStations = segs(1) & "," & segs(2) & "," & segs(3)
    Call ChangeLocalWorkStation(UserID,WorkStations)
wend




Sub ChangeLocalWorkStation(UserID,WorkStations)

     Dim server
     server = "DC1" ' Change this to the server you like to make changes on
     
     Dim Conn, Base, Filter, Attr, Tree, Root
     Set Conn = CreateObject("ADODB.Connection")
     Conn.Provider = "ADsDSOObject"
     Conn.Open "Active Directory Provider"
     
     Base   = "<LDAP://" & server & "/OU=Users,DC=Corp,DC=Net>;"  ' Change DC=CORP,DC=NET to your own
     filt   = "(&(objectClass=user)(objectCategory=person)(samAccountName=" & UserID & "));"
     Attr   = "distinguishedName;"
     Tree   = "SubTree"
     
     Dim rs
     Set rs = Conn.Execute(Base & filt & Attr & Tree)
     Dim dn, obj, wks
     rs.MoveFirst
     
                While Not rs.EOF
           dn = rs.Fields(0).Value
           Set obj = GetObject("LDAP://" & server & "/" & dn)
           obj.Put "userWorkstations", WorkStations
           obj.SetInfo
           wks = obj.Get("userWorkstations")
           Wscript.echo "Changed " & UserID & " userWorkstations to " & wks
           rs.MoveNext
     Wend
     
End Sub
0
Comment
Question by:fil1951
  • 2
3 Comments
 
LVL 71

Accepted Solution

by:
Chris Dent earned 500 total points
ID: 16331161

Should be easy enough to read whatever is there at the moment and append your new list onto the end of that:

strCurrentWorkstations = obj.Get("userWorkstations")
WorkStations = strCurrentWorkstations & "," & WorkStations
obj.Put "userWorkstations", Workstations
obj.SetInfo

HTH

Chris
0
 
LVL 1

Author Comment

by:fil1951
ID: 16334663
Works great! Thanks for your help.
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 16340501

No problem :)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month20 days, 13 hours left to enroll

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question