Results 1 to 6 of 6

Thread: find GUID for user account

  1. #1
    Chris Guest

    find GUID for user account

    I need to find the GUID in the string format
    (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). Using ADSI I only can get hex string
    format objectGUID. And don't know how to convert.

    Thanks,

  2. #2
    Richard Mueller [MVP] Guest

    Re: find GUID for user account

    The GUID property method converts to a string without the dashes.

  3. #3
    Richard Mueller [MVP] Guest

    Re: find GUID for user account

    The objectSid attribute is OctetString, which is a byte array. It can be
    converted to a hex string. The Guid property method returns the hex string
    format. There is another format with dashes and some bytes reversed. There
    may be other ways to deal with this, but in VBScript I have used code
    similar to the following to convert to the format you probably want:
    ================
    Option Explicit
    Dim objUser

    Set objUser = GetObject("LDAP://cn=Jim Smith,ou=Sales,dc=MyDomain,dc=com")

    Wscript.Echo objUser.Guid
    Wscript.Echo OctetToHexStr(objUser.objectGuid)
    Wscript.Echo ConvertHexStrGuidToStrGuid(OctetToHexStr(objUser.objectGuid))

    Function OctetToHexStr(arrbytOctet)
    ' Function to convert OctetString (byte array) to 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

    Function ConvertHexStrGuidToStrGuid(strOctet)
    Dim tempGuid, GuidStr
    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)

    TempGuid = "{" & Mid(GuidStr, 1, 8) & "-" & Mid(GuidStr, 9, 4) _
    & "-" & Mid(GuidStr, 13, 4) & "-" & Mid(GuidStr, 17, 4) _
    & "-" & Mid(GuidStr, 21, 15) & "}"

    ConvertHexStrGuidToStrGuid = tempGuid
    End Function

  4. #4
    Ryan Hanisco Guest

    RE: find GUID for user account

    Here is the microsoft article covering this...

    http://support.microsoft.com/default.aspx/kb/325648

  5. #5
    Chris Guest

    RE: find GUID for user account

    thanks for the article. Actually, what I need is opposite, converting hex
    to GUID.

  6. #6
    Chris Guest

    Re: find GUID for user account

    Richard,
    your script works great for me. I also found how to manually convert hex
    to GUID last night. For example: the hex string GUID is

    D416D85CD0D6EC47918913B83674F3C1

    to convert to GUID I need to reverse first 16 chars according to its "dash"
    format so the result will be

    5CD816D4-D6D0-47EC-9189-13B83674F3C1

    which is the same result from your script.

    Another question. Are you familar with repadmin /showmeta or /showobjmeta?

    I found I was able to run
    repadmin /showmeta "<5CD816D4-D6D0-47EC-9189-13B83674F3C1>" dc1.xxx.com

    but it doesn't work if using /showobjmeta. I have to use DN instead GUI.

    Any idea?

Similar Threads

  1. Standard User Account and User Account Controls Question
    By Susquehannock in forum Operating Systems
    Replies: 6
    Last Post: 06-08-2010, 06:08 AM
  2. Replies: 0
    Last Post: 07-01-2009, 08:18 PM
  3. Replies: 1
    Last Post: 27-11-2008, 01:29 AM
  4. can I view user account SID and GUID via ADSI
    By ridergroov in forum Active Directory
    Replies: 2
    Last Post: 11-06-2008, 11:51 PM
  5. How can I find out who created a user account in Active Directory
    By bubblecrumb in forum Windows Server Help
    Replies: 0
    Last Post: 13-02-2008, 01:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •