Edit script

Posted on 2006-03-29
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>


Set filesys = CreateObject("Scripting.FileSystemObject")

Dim myfile
If filesys.FileExists("macs.csv") Then
   Set myfile = filesys.OpenTextFile("macs.csv")
   MsgBox "Could not find file dbs.csv",0,"Error Finding File"
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)

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
                While Not rs.EOF
           dn = rs.Fields(0).Value
           Set obj = GetObject("LDAP://" & server & "/" & dn)
           obj.Put "userWorkstations", WorkStations
           wks = obj.Get("userWorkstations")
           Wscript.echo "Changed " & UserID & " userWorkstations to " & wks
End Sub
Question by:fil1951
    LVL 70

    Accepted Solution


    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


    LVL 1

    Author Comment

    Works great! Thanks for your help.
    LVL 70

    Expert Comment

    by:Chris Dent

    No problem :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    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…

    794 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now