Re: Search Filter to get a user's guid:
- From: "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 9 Apr 2009 08:14:17 -0500
<gimme_this_gimme_that@xxxxxxxxx> wrote in message
news:83fd2cf3-4f8b-4c8a-9cff-59e47d2ddffc@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm fetching user information using ADO and have the following:
strFilter = "(&(objectCategory=person)(objectClass=user)
(distinguishedName=CN=Doe\,
John,OU=Users,OU=Someplace,OU=Somewhere,OU=Americas,DC=west,DC=msds,DC=someco,DC=com)
(mail=*)(homemdb=*))"
attributes = "givenName,sn,mail"
strQuery = "<LDAP://" & strDNSDomain & ">;" & strFilter & ";" +
attributes + ";subtree"
This works.
If I change the attributes assignment to this:
attributes = "guid,givenName,sn,mail"
The query fails (there is no attribute named guid so I can understand
why)
Is there a way to get the GUID for this user?
Thanks.
The attribute name is objectGUID. The syntac is OctetString, which is a byte
array. I use a function to convert byte arrays to hex strings. For example:
=========
Set objUser = GetObject("LDAP://cn=Jim User,ou=West,dc=MyDomain,dc=com")
arrbytGuid = objUser.objectGUID
strGuid = OctetToHexStr(arrbytGuid)
Wscript.Echo strGUID
Function OctetToHexStr(arrbytOctet)
' Function to convert OctetString (Byte Array) to a hex string.
Dim k
OctetToHexStr = ""
For k = 1 To Lenb(arrbytOctet)
OctetToHexStr = OctetToHexStr _
& Right("0" & Hex(Ascb(Midb(arrbytOctet, k, 1))), 2)
Next
End Function
========
You must use a function similar to above if you retrieve the attribute value
with ADO. If you bind to the object, however, you can use the GUID property
method of the object. This method is a function that converts the value to a
hex string for you. For example:
======
Set objUser = GetObject("LDAP://cn=Jim User,ou=West,dc=MyDomain,dc=com")
strGuid = objUser.GUID
Wscript.Echo strGuid
=======
Other property methods of objects include Parent, Class, and AdsPath. Only
the later can be retrieved (and filtered on) using ADO.
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
.
- References:
- Search Filter to get a user's guid:
- From: gimme_this_gimme_that@xxxxxxxxx
- Search Filter to get a user's guid:
- Prev by Date: Re: Comparison of two AD user queries
- Next by Date: LDAP Group Query Results Limitation
- Previous by thread: Search Filter to get a user's guid:
- Next by thread: Vista - Burn to Cd
- Index(es):
Relevant Pages
|