Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove specific computer name in Logon Workstation from from all users in AD, with VBScript

Status
Not open for further replies.

Z3braa

IS-IT--Management
Sep 29, 2022
1
NO
In the users in our AD we have a specific computer name that result in only the user can logon to that very computer, called logon workstation. We also have a couple computers that are for "loan" if someone forgot theirs, that are added in the logon workstation besides with the specific computer that they already own.

There is a VBScript that we use every time a X amount of people start to work here so they also can access the loan PC (The VBScript add a self defined computer name to logon workstation to all the user). What we want help with is a VBScript that does actual the opposite, also remove that loan PC name from logon workstation from all the users. I will post the VBScript that add a specific computer name to Logon Workstation to all users if someone needs it or to get a bigger picture. Thanks


------------------------------------------------------------------

Option Explicit

Dim strComputer, objUser, strWorkstations, arrNames, k, objOU

' Bind to user object. Bytt ut OU=A,OU=4
Set objOU = GetObject ("LDAP://OU=PATH,OU=PATH,OU=PATH,OU=PATH,DC=PATH,DC=PATH")
objOU.Filter = Array("user")

' Specify NetBIOS name of computer to add.
strComputer = "XXXXXX"

For Each objUser in objOU
' Retrieve value of userWorkstations attribute.
strWorkstations = objUser.userWorkstations

' Check if new computer name already included.
arrNames = Split(strWorkstations, ",")
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
End If
Next

' Append new computer name.
If (strWorkstations = "") Then
strWorkstations = strComputer
Else
strWorkstations = strWorkstations & "," & strComputer
End If

' Save new value.
objUser.userWorkstations = strWorkstations
objUser.SetInfo

Next

------------------------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top