Go Back   TechArena Community > Technical Support > Computer Help > Windows Server > Active Directory
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: ,

Sponsored Links


find GUID for user account

Active Directory


Reply
 
Thread Tools Search this Thread
  #1  
Old 06-07-2007
Chris
 
Posts: n/a
find GUID for user account

Sponsored Links
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,

Reply With Quote
  #2  
Old 06-07-2007
Richard Mueller [MVP]
 
Posts: n/a
Re: find GUID for user account

Chris wrote:

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


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

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--


Reply With Quote
  #3  
Old 06-07-2007
Richard Mueller [MVP]
 
Posts: n/a
Re: find GUID for user account


"Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
message news:eOTqN50vHHA.484@TK2MSFTNGP06.phx.gbl...
> Chris wrote:
>
>>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.

>
> The GUID property method converts to a string without the dashes.
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>


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

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--


Reply With Quote
  #4  
Old 06-07-2007
Ryan Hanisco
 
Posts: n/a
RE: find GUID for user account

Chris,

Here is the microsoft article covering this...

http://support.microsoft.com/default.aspx/kb/325648
--
Ryan Hanisco
MCSE, MCTS: SQL 2005, Project+
Chicago, IL

Remember: Marking helpful answers helps everyone find the info they need
quickly.


"Chris" wrote:

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

Reply With Quote
  #5  
Old 06-07-2007
Chris
 
Posts: n/a
RE: find GUID for user account

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

"Ryan Hanisco" wrote:

> Chris,
>
> Here is the microsoft article covering this...
>
> http://support.microsoft.com/default.aspx/kb/325648
> --
> Ryan Hanisco
> MCSE, MCTS: SQL 2005, Project+
> Chicago, IL
>
> Remember: Marking helpful answers helps everyone find the info they need
> quickly.
>
>
> "Chris" wrote:
>
> > 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,

Reply With Quote
  #6  
Old 06-07-2007
Chris
 
Posts: n/a
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?


"Richard Mueller [MVP]" wrote:

>
> "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
> message news:eOTqN50vHHA.484@TK2MSFTNGP06.phx.gbl...
> > Chris wrote:
> >
> >>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.

> >
> > The GUID property method converts to a string without the dashes.
> >
> > --
> > Richard Mueller
> > Microsoft MVP Scripting and ADSI
> > Hilltop Lab - http://www.rlmueller.net
> > --
> >

>
> 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
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
>

Reply With Quote
Reply

  TechArena Community > Technical Support > Computer Help > Windows Server > Active Directory


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "find GUID for user account"
Thread Thread Starter Forum Replies Last Post
Standard User Account and User Account Controls Question Susquehannock Operating Systems 6 06-08-2010 06:08 AM
Transfer user settings to another user - Duplicate user's account (Windows Vista) TheGreatOne Tips & Tweaks 0 07-01-2009 08:18 PM
Windows could not find your user profile so it logged in to a temporary account.....! TABANL Vista Help 1 27-11-2008 01:29 AM
can I view user account SID and GUID via ADSI ridergroov Active Directory 2 11-06-2008 11:51 PM
How can I find out who created a user account in Active Directory bubblecrumb Windows Server Help 0 13-02-2008 01:00 PM


All times are GMT +5.5. The time now is 03:40 PM.