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

I give up - Need help searching for an AD user 1

Status
Not open for further replies.

keybrdcowboy

IS-IT--Management
Aug 31, 2004
96
US
I have been working on this for hours, and just don't know why it won't work. Keeps failing on the command.execut part, which tells me my search part is wrong. Just says there was a problem. Can anyone help? Thanks.




Option Explicit
Dim strFirstName, strLastName, strOfficeSymbol, strOrg, strTelNum, strEmailAdd, strStreetAdd, strCityAdd, strStateAdd, strZipAdd, strTitle
Dim strBofS, strUserName, objConnection, objCommand, objRecordSet, objRootDSE, strADsPath, objDomain

strUserName = InputBox("Please pick a username to find:")
fncCheckUserExist()

Function fncCheckUserExist()
Set objRootDSE = GetObject("LDAP://rootDSE")
strADsPath = "LDAP://" & objRootDSE.Get("defaultNamingContext")
Set objDomain = GetObject(strADsPath)

wscript.echo strADsPath

Set objConnection = CreateObject("ADODB.Connection")
objconnection.provider = "ADsDSOObject"
objConnection.Open
'"Provider=ADsDSOObject"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

objCommand.CommandText = strADsPath & ";(&(objectClass=user)(Full Name=mobleyj));sAMAccountName;subtree"
' "(sAMAccountName=" & strUserName & "));" & "sAMAccountName, distinguishedName;subtree"

Set objRecordSet = objCommand.Execute

If objRecordSet.RecordCount = 0 Then
strUserName = strUserName
Else
While Not objRecordset.EOF
strUserName = "none"
Wend
End If
End Function

If strUserName = "none" Then
Wscript.echo "That username is already in use; please choose another!"
strUserName = InputBox("Please choose a different username; Must be unique")
fncCheckUserExist()
Else
wscript.echo "Username Found!!"
wscript.Exit
End If
 
Thanks a lot.... working great now. Only thing I changed was telling it to search the GC instead of all of AD.....
 
I've found those functions very helpful myself. Glad you got it working.

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top