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,
Printable View
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,
The GUID property method converts to a string without the dashes.
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
Here is the microsoft article covering this...
http://support.microsoft.com/default.aspx/kb/325648
thanks for the article. Actually, what I need is opposite, converting hex
to GUID.
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?