For each array results displaying on seperate lines

Hi There

Newbie here, trying to get my results to appear in two columns on one line…

$results = $files | ForEach-Object { $ ; $ | Get-Content | Measure-Object -Line}

$results | Format-Table Name,Lines

Name Lines


(A01) SerialAmendments.csv

9

(A02) New Meters.csv

89

(A03) Disconnected Meters Pelican.csv

4

any help appreciated :slight_smile:

Well,

What you need here is just a Select-Object cmdlet. You can use calculated properties to do the measure. I would like you to have a try before adding some code. Below link will help you to do that.

https://www.pdq.com/blog/powershell-tips-for-system-administrators-calculated-properties/

PS: Format-Object cmdlet is supposed to be used only when intent is just to display the output in console as it completely destroys the objects by formatting it to text which becomes non usable when consumed by other cmdlet.

finally, please use below instructions to post the code with code formatting options.
https://powershell.org/forums/topic/read-me-before-posting-youll-be-glad-you-did/

Thanks! This is what I ended up with, thanks for the link it was very helpful. :slight_smile:

$results = $files | Select-Object -Property `
@{ N = 'name' ; E = { $_.Name}},
@{ N = 'modification_date' ; E = { $_.LastWriteTime} },
@{ N = 'row_count'; E = { ($_ | Get-Content | Measure-Object -Line).Lines } }

Why do you rename the property “Name” to “name”?