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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return users in AD

Status
Not open for further replies.

systechguy37

Technical User
Sep 5, 2010
1
US
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 am having a hard time understanding why you want to do what you are trying to do. Asking a user for their domain at login is certainly not best practice and is not very practical. A user could enter the wrong information and then get the wrong drive mappings or none at all.

Please take a look at my login script FAQ which can give you all the code you should need to perform your drive mappings and much more.




I hope that helps.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top