Share via


Rearrange output from multiple lines to one line separated by commas

Question

Monday, July 30, 2012 1:39 PM

I would like to change the output of a powershell script from multiple lines to one line separated by commas.  Here is an example of the script I am staring with and the desired output:

get-aduser | select samAccountName -> normally gives you:

jsmith
rhuskey
thill

I'd like to have:

jsmith,rhuskey,thill

Is there any way to do that?

All replies (1)

Monday, July 30, 2012 1:45 PM âś…Answered | 2 votes

A couple of possibilities:

(get-aduser -filter * | select -expand samAccountName) -join ','

or

$ofs = ','[string](get-aduser -filter * | select -expand samAccountName)

[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "