objectGUID returns 'System.Byte[]' when using Query AD activity

shill
Mega Sage

I am needing to update a user record that was created outside of the LDAP import with its objectGUID value as that is what our LDAP import uses to coalesce on.

I am using the Query AD orchestration activity and returning the proper user data.

But in the return json, I am getting "objectguid":"System.Byte[]" instead of something like /v5pExxhx0uGQq0UTNbs9g== .   The latter is what is provided in the LDAP import.

Is it possible to retrieve the same value as the LDAP import would receive via this activity?  

This is part of our onboarding process, so I need update the new record so that the LDAP import does not duplicate the user.

1 ACCEPTED SOLUTION

Robert Beeman
Kilo Sage

I'm doing this by passing AD's GUID property into this PoSh function:


function Get-B64($guid) {


  [System.Convert]::ToBase64String((new-Object system.Guid($guid)).ToByteArray())


}


View solution in original post

12 REPLIES 12

Alex Mittell
ServiceNow Employee
ServiceNow Employee

I think you need to convert it to a string as it's coming back as a byte array, something like;



new Guid((System.Byte[])this.GUID).ToString()



There's a few posts about doing the conversion here: mobile - How do I convert an Active Directory objectGuid to a readable string? - Stack Overflow


Robert Beeman
Kilo Sage

I'm doing this by passing AD's GUID property into this PoSh function:


function Get-B64($guid) {


  [System.Convert]::ToBase64String((new-Object system.Guid($guid)).ToByteArray())


}


Also, I use this PoSh function to go the other way around:


function Get-Guid($base64) {


  (new-Object -TypeName System.Guid -ArgumentList(, ( ([System.Convert]::FromBase64String($base64)) ) )).Guid


}


Robert,


How would I use this in my situation? I am using the baseline Query AD workflow activity and then a run script activity with the below script.


I would think a powershell function would need to go in the Query AD powershell command.



var qry = new JSON();


qry = qry.decode(sanitizeResults(workflow.scratchpad.queryAD));



workflow.scratchpad.guid = qry['objectguid'];


gs.log(workflow.scratchpad.guid);



function sanitizeResults(qry) {


  qry = qry.replace(/<\/*(powershell|output)>/g, "");


  qry = qry.replace(/((^\[)|(\]$))/g, "");


  return qry;


}