That's a key reason we don't use ChatGPT for production coding - that's very inefficient. It also is building a string with a delimiter and then removing the final delimiter. A much better method would be
 Code:
$Delim = ''
For Each $Elem in $aArray
  $String = $String + $Delim + $Elem
  $Delim = ','
Next
$String @CRLF
However, this is what most experienced coders would do:
 Code:
$aArray = Function(args..)
'DEBUG - Array data contains: Join($aArray, ' | ') ; or use @CRLF delimiter for 1 val per line
When we're debugging/developing apps and want to visualize the data being returned from functions, we use the DispResult() function. Pass it a variable and it figures out what KIND of variable it is and displays the type and value - simple ITEM, ARRAY, or 2-D ARRAY values are supported. The version on my website doesn't support COMPOUND ARRAY types, but those are not commonly used.

DispResult function: https://www.barnas.us/Downloads/Kixlib/DispResult.kxf.htm

The bottom line is that you are trying to directly display a value that is being returned as an array. You need to read the headers of the UDF to determine what is being returned and process it appropriately. GetGroups indicates it returns a 2-dimension array. GetADUserGroups also reports that it returns an array. If you don't know what kind of data is being returned or defined in a variable, the VarType() and VarTypeName() functions can help.

Also - public UDFs are "black boxes" and meant to be used as published. Removing code can break functionality, and - in essence - you are creating a NEW function and should thus give it a new name and header. Failing to do that will cause the rest of us to waste time troubleshooting something we believe to be a standard when it isn't. This isn't the first time we've had a discussion about understanding the data you are working with..


Edited by Glenn Barnas (2023-06-28 04:00 PM)
_________________________
Actually I am a Rocket Scientist! \:D