Results from Powershell to Comma Separated String

Question:

I have the below script that I run, how can I get the output to be placed into a comma separated string?

Current Output

Desired Output

I am passing this into a string and parsing the data remotely using JavaScript.

Answer:

That’s fairly easy and consists of two steps: First separating the GUID and account name with a comma:


and then joining all those strings with a comma into a single string:

We could also do it differently: First decompose the objects into simply two strings:

and then joining all those with a comma:

or take advantage of the $OFS variable which specifies with what separator arrays are converted to strings. Same start, we need a single array with everything that should be joined with a comma, and then we set the $OFS variable and convert the array to a string:

Source:

Results from Powershell to Comma Separated String by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply