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!
[!]The AutoSavers![/!]![[2thumbsup] [2thumbsup] [2thumbsup]](/data/assets/smilies/2thumbsup.gif)
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] [2thumbsup] [2thumbsup]](/data/assets/smilies/2thumbsup.gif)