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

script to determine OU of user

Status
Not open for further replies.

cbsarge

IS-IT--Management
Jun 20, 2001
219
US
I have the following script which doesn't work yet. If I were to put in the username for each time I run the script it would work but, I want it to work with an InputBox variable (strUserName) so I don't have to edit the script each time. I've tried a bunch of different syntax but, haven't been able to get it working yet.

Thanks for the help!
Code:
On Error Resume Next
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
strUserName = InputBox("Enter the name of the user:")
If strUserName = "" Then
    MsgBox "One or more required fields where left blank.", vbOKOnly, "Error"
    vbscript.quit
End If
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 

objCommand.CommandText ="SELECT distinguishedName FROM 'LDAP://dc=mydomain,dc=com' WHERE objectCategory='user' AND samAccountName="" & strUserName & """
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    Wscript.Echo objRecordSet.Fields("distinguishedName").Value
    objRecordSet.MoveNext
Loop

[!]The AutoSavers![/!] [2thumbsup]
 
Code:
AND samAccountName='" & strUserName & "'"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top