Based on this SO question Powershell: Output collection of objects, I am able to wrap a collection of strings in multiple lines in one column. However, when I try to output the collection to table-view, the autosize would not allow me to specify specific column width.
For example:
id name items others
--- ---- ----- -----
01 a ("The first item", "The second item", "The third item", "...") ...
02 ....
Here is my output:
$colObjs | Select-object id, name, items, others`
@{Expression={($_.items -join "`n")};Label="Items"} | `
Format-table -autosize -wrap
Then the items column would be the whole length of strings in its array:
id name items others
--- ---- ----- -----
01 a "The first item" ...
"The second item" ....
"The third item"
...
02 ....
I tried to use the following codes, still the width of items column not as expected:
$colObjs | Select-object id, name, items, others `
@{Expression={($_.items -join "`n")};Label="Items"} | `
Format-table id, name, `
@{expression={$_.items}; label="items"; width=18}, others `
-autosize -wrap
Specially, if the items have a long list of strings, the table view looks very ugly, too much spaces in column items.
This is the format what I want:
id name items others
--- ---- ----- -----
01 a "The first item" ...
"The second item" ....
"The third item"
...
02 ....
Is this true that -autosize would make width having no effect? How can I specify the width of items and leave other columns as auto-sized?