Skip navigation

Rem: Retrieving the Value of the ObjectGUID Attribute


I'm trying to retrieve the value of an Active Directory (AD) user object's objectGUID attribute with the code that Listing 1 shows. But when I run this code, I receive a string of question marks, as Figure 1 shows. How can I retrieve this value?

The code to retrieve the objectGUID value can be amazingly simple or moderately complex. The simple solution uses the IADs::GUID helper property in lieu of accessing the objectGUID attribute directly. Listing 2 demonstrates how easy using the IADs::GUID property is. When you run the code in Listing 2, you should get output more to your liking, as the second entry in Figure 1 shows.

The moderately complex solution involves manually converting the objectGUID value to a string, as Listing 3 shows. Listing 3 should also produce the results you're looking for, as the third entry in Figure 1 shows.

Why does IADs::GUID work but objectGUID doesn't without jumping through hoops? IADs::GUID works because AD stores the objectGUID value as an octet string. An octet string is an array of bytes that's used to store binary data. When you use the IADs::GUID property to retrieve the objectGUID value, Active Directory Service Interfaces (ADSI) takes care of converting the octet string into a usable string for you. If you want to access objectGUID directly, converting the octet string into a usable string is up to you.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.