Search code examples
powershellactive-directorydsquery

Get-ADGroup returns different ObjectGUID than dsquery


Can someone explain how to get the ObjectGUID the same as is returned from dsquery except using powershell?

As an example.

Powershell

Get-ADGroup "MyGroup" -Properties ObjectGUID
32359aec-2e77-4b0c-b525-3e9a39083314

dsquery (application uses DSQuery don't have the command it uses)

7Jo1MncuDEu1JT6aOQgzFA==

Edit - For clarity, I want to query the AD Group in powershell and get the DSQuery result for ObjectGUID. I do not want the powershell result for ObjectGUID.


Solution

  • The output from dsquery is the raw underlying binary GUID, base64-encoded.

    To convert between the two formats:

    # GUID to base64
    $guidInstance = [guid]::new('32359aec-2e77-4b0c-b525-3e9a39083314')
    [convert]::ToBase64String($guidInstance.ToByteArray())
    
    # base64 to GUID
    $binaryGUID = [convert]::FromBase64String('7Jo1MncuDEu1JT6aOQgzFA==')
    [guid]::new($binaryGUID)