"jnet77" <jnet77@xxxxxx> wrote in message
news:F13662A0-F432-4E68-BB30-5C86865C75E6@xxxxxx
> Richard,
>
> Thanks for the response, and what you suggested is originally how the
> script
> worked. The problem was, though, if I had 500 students and the 100th one
> already had the computer, the script would end at student 100. That meant
> the other 400 wouldn't get the new computer added.
>
> I need the script to only not execute on a user when the computer is
> already
> found, but then go on and move to the next user.
>
> Your assistance in advance is appreciated. Then one solution would be a boolean variable to indicate if the name is
found. For example (in part):
========
Dim blnFound
For Each objUser in objOU
' Retrieve value of userWorkstations attribute.
strWorkstations = objUser.userWorkstations
' Check if new computer name already included.
arrNames = Split(strWorkstations, ",")
blnFound = False
For k = 0 To UBound(arrNames)
If (LCase(strComputer) = LCase(arrNames(k))) Then
' This computer already included. Abort.
Wscript.Echo "User already allowed to logon to " & strComputer
blnFound = True
Exit For
End If
Next
If (blnFound = False) then
' Append new computer name.
If (strWorkstations = "") Then
strWorkstations = strComputer
Else
strWorkstations = strWorkstations & "," & strComputer
End If
' Save new value.
objUser.userWorkstations = strWorkstations
objUser.SetInfo
End If
Next
=========
Note that the "Exit For" statement exits from the inner "For" statement, not
the outer "For Each".
--
Richard Mueller
MVP Directory Services
Hilltop Lab -
http://www.rlmueller.net
--