Re: Get ADsPath W2K user
- From: Richard W <RichardW@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 26 Apr 2007 09:20:04 -0700
Hello Richard,
Unfortunately this still does not work. I'm beginning to think that this
problem is nog related to the scipt itself, but something else. Anyway, when
I run the script in which I have adapted according to your suggestions, I
receive the following error:
"A referral was returned from the server"
The source provide in this case is 'provider', and the error code is
8007202B. Also, I pasted the code of the script below.
strUserName = "testuser"
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText =
"<LDAP://dc=testdomain,dc=local>;(&(objectCategory=person)(objectClass=user)(sAMAccountName=" & strUserName & "));AdsPath;subtree"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.eof
strField = objRecordSet.Fields("AdsPath")
WScript.Echo strField
objRecordSet.MoveNext
Loop
objConnection.Close
Any suggestions?
"Richard Mueller [MVP]" wrote:
First, remove "On Error Resume Next" in case this is masking an error.
message that could help troubleshoot. There is no need to disable normal
error handling. Next, I would use:
"(&(objectCategory=person)(objectClass=user)(sAMAccountName=" & strUserName
& "))"
In fact, since sAMAccountName must be unique in the domain, you should be
able to use:
"(sAMAccountName=" & strUserName & ")"
Finally, remove the space after AdsPath where you retrieve the value. It
should be:
strField = objRecordSet.Fields("AdsPath")
Otherwise, the code looks good and should work the same on W2k and W2k3.
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
"Richard W" <RichardW@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:1F22D756-A0EF-4213-94CB-4FE5564CFF5B@xxxxxxxxxxxxxxxx
Hello all,
I am trying to search a Windows 2000 domain for users, and then get back
the
AdsPath, for example cn=testuser,ou=accounts,dc=testdomain,dc=local. I
have a
piece of code that already successfully used in a Windows Server 2003
domain,
but when I try this script in a Windows 2000 domain I receive the error:
“A referral was returned from the server”
The script contains the following code:
On Error Resume Next
strUserName = "testuser"
dtStart = TimeValue(Now())
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
"<LDAP://dc=testdomain,dc=local>;(&(objectCategory=User)" & _
"(samAccountName=" & strUserName & "));AdsPath;subtree"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.eof
strField = objRecordSet.Fields("AdsPath ")
WScript.Echo strField
objRecordSet.MoveNext
Loop
objConnection.Close
Does anybody know what’s the problem here? Or is there maybe a different
way
I can search a Windows 2000 domain based on accountname, and which
returnes
the AdsPath or CN?
Many thanks in advance.
Regards,
Richard
- References:
- Re: Get ADsPath W2K user
- From: Richard Mueller [MVP]
- Re: Get ADsPath W2K user
- Prev by Date: Re: Setting rights on an AD account using vb
- Next by Date: Re: convert string to decimal
- Previous by thread: Re: Get ADsPath W2K user
- Next by thread: Re: convert string to decimal
- Index(es):
Relevant Pages
|