Re: Search Filter to get a user's guid:

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




<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
--


.



Relevant Pages

  • Re: GUID mit VBScript erzeugen
    ... hab ich doch glatt das "D" bei GUID überlesen. ... the home of WSH Bazaar & more "Martin" schrieb im Newsbeitrag ... > dim strGUID dim obj ...
    (microsoft.public.de.german.scripting.wsh)
  • Re: Uniqueidentifier gespeicherte Procedure
    ... > Function SQLServerStringFromGUIDAs String ... > ' Ändert das Access GUID Format in das SQL Server Format ... > Dim strGuid As String ...
    (microsoft.public.de.access.clientserver)
  • Re: How can I generate a GUID?
    ... > identifier. ... Are you sure you're using Guid.NewGuid() and not just Guid? ... Guid.ToString returns all zeros. ... Dim strGUID As String ...
    (microsoft.public.dotnet.languages.vb)
  • Re: für Netzwerkkarte MAC-Adresse setzen via Script?
    ... strGUID = CStr.guid) ... Glaube aber nicht, daß dir das viel bringt, da man nur sagen kann "Erzeuge ... Eine GUID ist eindeutig, aber per ... der GUID, des Adapters, den der Benutzer ausgewählt hat. ...
    (microsoft.public.de.german.windowsxp.registry)