Terminal Service profile is not an AD attribute
WARNING: Not an Active Directory attribute Terminal Services Attributes are accessed via the IADsTSUserEx interface.  You may receive an “Object doesn’t support this property or method” error when you try to run the code.  This error will probably indicate that you don’t have the “TsUserEx.dll” file is required to run this code.

'=================
Option Explicit

Dim adoCommand, adoConnection, strBase, strFilter, strAttributes
Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strDN , strOUPath
Dim objUser

Const ADS_PROPERTY_CLEAR = 1

' Setup ADO objects.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection

strOUpath = "OU=test,"

' Search entire Active Directory domain.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & stroupath & strDNSDomain & ">"

' Filter on user objects with a value assigned to scriptPath.
strFilter = "(&(objectCategory=person)(objectClass=user))"

' Comma delimited list of attribute values to retrieve.
strAttributes = "distinguishedName"

' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False

' Run the query.
Set adoRecordset = adoCommand.Execute

' Enumerate the resulting recordset.
Do Until adoRecordset.EOF

    ' Retrieve values.
    strDN = adoRecordset.Fields("distinguishedName").Value

    ' Bind to user object.
    Set objUser = GetObject("LDAP://" & strDN)

WScript.Echo objUser.Name, objUser.AllowLogon

    ' Clear the allowlogon attribute.
      objUser.TerminalServicesProfilePath = "\Servershare"
      objuser.scriptPath = "loginscript.bat"
      objUser.setinfo

    ' Save changes.
    'objUser.SetInfo

WScript.Echo objUser.Name
    ' Move to the next record in the recordset.
    adoRecordset.MoveNext
Loop

' Clean up.
adoRecordset.Close

adoConnection.Close
'============ 
objUser.Put "homeDirectory", "\hu.lcldfsuser<username>"
objUser.Put "homeDrive", "U:"
Tags

Comments are closed