Home » loop

Tag: loop

SCRIPT: loop through users CN, tsprofile paths and userParameters

‘vbscript
Option Explicit
Dim objCommand, objConnection, strBase, strFilter, strAttributes, objUser
Dim strQuery, objRecordset, strdistinguishedName, strTSPath, strCN, objFSO,
Set objCommand = CreateObject(“ADODB.Command”)
Set objConnection = CreateObject(“ADODB.Connection”)
objConnection.Provider = “ADsDSOObject”
objConnection.Open “Active Directory Provider”
objCommand.ActiveConnection = objConnection
Const ForWriting = 2
‘…set the base DN
strBase = “<ldap://DC=domain,DC=/local>”
strFilter = “(&(objectCategory=person)(objectClass=user))”
strAttributes = “sAMAccountName,cn,distinguishedName”
strQuery = strBase & “;” & strFilter & “;” & strAttributes & “;subtree”
objCommand.CommandText = strQuery
objCommand.Properties(“Page Size”) = 100
objCommand.Properties(“Timeout”) = 30
objCommand.Properties(“Cache Results”) = False
Set objRecordSet = objCommand.Execute
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Do Until objRecordSet.EOF
  strdistinguishedName = objRecordSet.Fields(“distinguishedName”).Value
  Set objUser = GetObject(“LDAP://” & strdistinguishedName)
  On error resume next
 wscript.echo “User:” & objUser.cn & vbtab &  “UserParameters:” & objUser.userParameters & vbtab & ” TSProfilePath:” & objUser.TerminalServicesProfilePath
 ‘ & objUser.sAMAccountName _
  ‘& “,” & objUser.TerminalServicesProfilePath & “,” & objUser.profilePath _
 ‘ & “,” & objUser.homeDirectory & “,” &objUser.ScriptPath
 ‘ objRecordSet.MoveNext
  objRecordSet.MoveNext
Loop
objConnection.Close