systechguy37
Technical User
I am trying to create a vbscript that will return all users in Active Directory that will map client drives and local printers at login (terminal services).
I have a basic script that works, but this is a very large AD (over 2000 users) and I would like to use the ADO object and return my results to a Record Set. This is my basic script:
-----------------------------------------------------------
Sub ListUsers( strDomain )
Set objComputer = GetObject("WinNT://" & strDomain )
objComputer.Filter = Array( "User" )
For Each objUser In objComputer
Wscript.echo objUser.FullName
if objUser.ConnectClientDrivesAtLogon = 1 then
WScript.echo "ConnectClientDrivesAtLogon are enabled"
end if
if intConnectClientPrintersAtLogon = 1 then
WScript.echo "ConnectClientPrintersAtLogon are enabled"
end if
WScript.Echo ""
Next
End Sub
' ****************************************************************************
' Main
' ****************************************************************************
Dim strDomain
Do
strDomain = inputbox( "Please enter a domainname", "Input" )
Loop until strDomain <> ""
ListUsers( strDomain )
---------------------------------------------------------
I am somehow trying to combine it with the following script, but I do not know how to write an LDAP query that will return only users that will map local drives and printers at login.
-------------------------------------------------------
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select Name, Location from 'LDAP://DC=mmsasp,DC=local' " _
& "Where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value
Wscript.Echo "Location: " & objRecordSet.Fields("Location").Value
objRecordSet.MoveNext
Loop
-------------------------------------------------------
Any assistance would be appreciated.
I have a basic script that works, but this is a very large AD (over 2000 users) and I would like to use the ADO object and return my results to a Record Set. This is my basic script:
-----------------------------------------------------------
Sub ListUsers( strDomain )
Set objComputer = GetObject("WinNT://" & strDomain )
objComputer.Filter = Array( "User" )
For Each objUser In objComputer
Wscript.echo objUser.FullName
if objUser.ConnectClientDrivesAtLogon = 1 then
WScript.echo "ConnectClientDrivesAtLogon are enabled"
end if
if intConnectClientPrintersAtLogon = 1 then
WScript.echo "ConnectClientPrintersAtLogon are enabled"
end if
WScript.Echo ""
Next
End Sub
' ****************************************************************************
' Main
' ****************************************************************************
Dim strDomain
Do
strDomain = inputbox( "Please enter a domainname", "Input" )
Loop until strDomain <> ""
ListUsers( strDomain )
---------------------------------------------------------
I am somehow trying to combine it with the following script, but I do not know how to write an LDAP query that will return only users that will map local drives and printers at login.
-------------------------------------------------------
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select Name, Location from 'LDAP://DC=mmsasp,DC=local' " _
& "Where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value
Wscript.Echo "Location: " & objRecordSet.Fields("Location").Value
objRecordSet.MoveNext
Loop
-------------------------------------------------------
Any assistance would be appreciated.