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

Active Directory VBScript Problem

Status
Not open for further replies.

djtech2k

MIS
Jul 24, 2003
1,097
US
I am having a very strange result of some scripts. The issue is that it returns NO values even though I know it should. Here is some info:

Environment: W2k3, Exch2k3 – Multiple Domains with Empty Forest Root
Desktop: Vista and XP


I am using ADO with the LDAP query to AD that I have used thousands of times. There are no errors. I can take out the LDAP filter and use it in ADUC with no problems. I have removed everything and it still does not work.

I am logged into “Domain A”. I use the RootDSE to get the defaultnamingcontext, so it dynamically would get his domain. There were no results, so I backed up and tried to get a record count from the ADO and it was coming back 0. So I hard-coded the DC and DN of the root search and it still was 0. I then hard-coded the root to a specific OU and it showed a large record count, but none of the values were echoed out. So it is finding results finally, but it refuses to echo them out. Have any of you had this happen?


Here is an example of the parts I mentioned:

Filter: LDAP://OU=UserStuff,DC=sub,DC=domain,DC=com


For example, this very generic script returns NO results:

Code:
Option Explicit

Dim objRootDSE, strDNSDomain, objCommand, objConnection, strQuery, strBase, strFilter, strAttributes
Dim objRecordSet, strAlias, strName, strSAM
Dim blnFlag

' Determine DNS domain name from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

' Use ADO to search Active Directory.
Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection

' Search for all user objects. Return Values.
strBase = "<LDAP://" & strDNSDomain & ">"
strFilter = "(&(objectCategory=person)(objectClass=user))"
strAttributes = "displayName,mailNickname,sAMAccountName"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
objCommand.Properties("Sort On") = "displayName"
Set objRecordSet = objCommand.Execute
  
    Do Until objRecordSet.EOF
  strName = objRecordSet.Fields("displayName")
  strAlias = objRecordSet.Fields("mailNickname")
  strSAM = objRecordSet.Fields("sAMAccountName")
  Wscript.Echo strSAM & " ; " & strAlias & " ;   " & strName
  	
    objRecordSet.MoveNext
	Loop

objConnection.Close

Any ideas? I was puzzled why no records were found and then even when they are found, it refuses to echo out the varaibles or anything else in the loop.
 
First, comment out the "Sort On" line. It is known server-side sort may pose problem in various circumstances. If it resolves the mystery, implement client-side sort afterward if you like.
 
Code works fine. Try a different machine.

You state that you're in multiple domains, can you be more specific as to which domain you are logged into?


PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
I am actually helping someone out with this, so I am not logged into anything.

I will try to comment out the sort and try again. I have used this script in tyhousands of environments, but this one is the only one that fails. I have had the guy try it from a vista and xp desktop. Both have same results. I saw it happen via livemeeting.

The story is that there is more than 1 domain. He is logged into domain A and wants to query only domain A. I I let it find the domain/dc dynamically, it shows recordcount of zero. If I hardcode a Dc and OU, then it shows a recordcount, but it never echo's anything out. Its the strangest thing I have seen.

I can prove the ADO search is good because of the recordcount after I hard code the DC/OU. I just cannot get any values.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top