Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
vktr
Regular Visitor

Active Directory (AD) User Object GUID

Hello,

 

Has anyone managed to get User Object GUID from Active Directory (AD)?

It is in binary format so it must be converted to text to use it.

 

There is an example on how to convert Object SID binary to text.

Also I saw a topic where MS Graph is used to get GUID, but it only applies to Azure AD, so it would not help in my case.

1 ACCEPTED SOLUTION
vktr
Regular Visitor

I needed this to link AD objects to Azure AD objects.

I have found that it is enough for me to convert AD GUID values with function:

= Binary.ToText(Guid, 0)

In Azure AD GUID's have the same expression as after confersion with function above.

 

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Thread revival from the grave, total PowerBI beginner.  How are you implementing;

 

= Binary.ToText(Guid, 0)

 

From the solutions above?

v-ljerr-msft
Microsoft Employee
Microsoft Employee

Hi @vktr,


Has anyone managed to get User Object GUID from Active Directory (AD)?

It is in binary format so it must be converted to text to use it.

 

There is an example on how to convert Object SID binary to text. 

I just verified that I can successfully use the M query below which is provided in that thread to get User Object GUID from Active Directory (AD). Smiley Happy

let
    ConvertSidToStringSid = (sid) => let
        parts = BinaryFormat.Record([
            version = BinaryFormat.Byte,
            count = BinaryFormat.Byte,
            first = BinaryFormat.List(BinaryFormat.Byte, 6),
            rest = BinaryFormat.List(BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger32, ByteOrder.LittleEndian))])(sid),
        result = "S-" & Number.ToText(parts[version]) & "-" & Number.ToText(BinaryFormat.UnsignedInteger64(#binary({0, 0} & parts[first]))) & List.Accumulate(parts[rest], "", (a, b) => a & "-" & Number.ToText(b))
    in
        result,
    Source = ActiveDirectory.Domains("redmond.corp.microsoft.com"),
    redmond.corp.microsoft.com = Source{[Domain="redmond.corp.microsoft.com"]}[#"Object Categories"],
    user1 = redmond.corp.microsoft.com{[Category="user"]}[Objects],
    FilteredRows = Table.SelectRows(user1, each [displayName] = "Curt Hagenlocher"),
    #"CN=Curt Hagenlocher,OU=UserAccounts,DC=redmond,DC=corp,DC=microsoft,DC=com" = FilteredRows{[distinguishedName="CN=Curt Hagenlocher,OU=UserAccounts,DC=redmond,DC=corp,DC=microsoft,DC=com"]}[securityPrincipal],
    objectSid = #"CN=Curt Hagenlocher,OU=UserAccounts,DC=redmond,DC=corp,DC=microsoft,DC=com"[objectSid],
    stringSid = ConvertSidToStringSid(objectSid),
    #"Converted to Table" = #table(1, {{stringSid}})
in
    #"Converted to Table"

r1.PNG

 

Regards

Hi @v-ljerr-msft,

 

Yeah i know Smiley Happy I do use it for getting AD object's SID.

But as I've said, I needed to extract GUID value.

GUID is different from SID, so needed another solution to convert GUID's binary value to text, which turned up, is an eazy task.

 

Anonymous
Not applicable

@vktr did u find solution?...i have similar issue

vktr
Regular Visitor

I needed this to link AD objects to Azure AD objects.

I have found that it is enough for me to convert AD GUID values with function:

= Binary.ToText(Guid, 0)

In Azure AD GUID's have the same expression as after confersion with function above.

 

Not sure where or how to add this function. Anymore details available? 

camydee
Microsoft Employee
Microsoft Employee

Binary.ToText won't actually do what you want. This simply translates the bytes in sequence, which does not follow RFC 4122 GUID Format.

 

Try this:


Binary.ToTextGuid = (binaryGuid) =>
let
   Number.To2DigitHex = each Text.End("0"& Number.ToText(_, "X"),2),
   HexBytes = List.Transform(Binary.ToList(binaryGuid), Number.To2DigitHex),
   Result = Text.Format("#{3}#{2}#{1}#{0}-#{5}#{4}-#{7}#{6}-#{8}#{9}-#{10}#{11}#{12}#{13}#{14}#{15}", HexBytes)
in Result,


Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.