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

ADSI / VBScript / Search AD via objectGUID

Status
Not open for further replies.

djhawthorn

Technical User
Joined
Mar 4, 2002
Messages
641
Location
AU
I need to search Active Directory to find an object (if it exists) by its GUID. I have the following code:

Code:
'GUID of object: {D5E43637-B3CE-4E80-A276-F70F82B7CF3C}

Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

objCommand.ActiveConnection = objConnection
strBase = "<LDAP://dc=retra3000,dc=com>"
strFilter = "(&(objectGuid=\D5\E4\36\37\B3\CE\4E\80\A2\76\F7\0F\82\B7\CF\3C))"
strAttributes = "displayName"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute

WScript.Echo objRecordSet.RecordCount & " objects found."

objConnection.Close

But it doesn't work - it always returns 0 objects, even though the object with that GUID exists.

I must be doing something wrong - ideas? Solutions? Any help greatly appreciated!

[auto] MCSE NT4/W2K
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top