How to retrieve the GUID of an object from the Active Directory

Article translations Article translations
Article ID: 325649 - View products that this article applies to.
This article was previously published under Q325649
Expand all | Collapse all

SUMMARY

This article demonstrates how to convert the hexadecimal string form of an object's GUID into its string form:
  1. Paste the following code in a .vbs file.
    
    '================================================================
    'Set the next line to reflect a DN for an object in the directory
    '================================================================
    Set obj = GetObject("LDAP://CN=Username,CN=Users,DC=DOMAIN,DC=COM")
    MsgBox "The GUID string Value for user " & obj.Get("DisplayName") & _
           " is " &  ConvertHexStringGUIDToStringGUID(obj.GUID)
    
    '================================================================
    ' ConvertHexStringGUIDToStringGUID function
    '================================================================
    Function ConvertHexStringGUIDToStringGUID(strOctet)
        Dim tmpGUID, GUIDStr
        'Convert the string by flipping the bits around.
        GUIDStr = Mid(strOctet, 7, 2)
        GUIDStr = GUIDStr + Mid(strOctet,  5, 2)
        GUIDStr = GUIDStr + Mid(strOctet,  3, 2)
        GUIDStr = GUIDStr + Mid(strOctet,  1, 2)
        GUIDStr = GUIDStr + Mid(strOctet, 11, 2)
        GUIDStr = GUIDStr + Mid(strOctet,  9, 2)
        GUIDStr = GUIDStr + Mid(strOctet, 15, 2)
        GUIDStr = GUIDStr + Mid(strOctet, 13, 2)
        GUIDStr = GUIDStr + Mid(strOctet, 17, Len(strOctet))
    
        tmpGUID = "{" & Mid(GUIDStr,  1,  8) & "-" & Mid(GUIDStr,  9, 4) & _
                  "-" & Mid(GUIDStr, 13,  4) & "-" & Mid(GUIDStr, 17, 4) & _
                  "-" & Mid(GUIDStr, 21, 15) & "}"
    
        ConvertHexStringGUIDToStringGUID = tmpGUID
    End Function
    
    					
  2. Run the script.

Properties

Article ID: 325649 - Last Review: March 29, 2007 - Revision: 3.0
APPLIES TO
  • Microsoft Windows 2000 Standard Edition
  • Microsoft Active Directory Service Interfaces 2.5
  • Microsoft Active Directory Service Interfaces 2.5
Keywords: 
kbhowtomaster kbdswadsi2003swept KB325649

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com