Edit script

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
LVL 1
fil1951Asked:
Who is Participating?
 
Chris DentPowerShell DeveloperCommented:

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
 
fil1951Author Commented:
Works great! Thanks for your help.
0
 
Chris DentPowerShell DeveloperCommented:

No problem :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.