How to auto-adjust column widths to max value length

The best way to show my problem is to show a sample.
When I execute (on Win10 21H2) a PS command like:

Get-PnpDevice | where name -match mass

then in the resulting table some columns are

  • wider than necessary
  • small then necessary (some values are cut)

How can I tell PS to automatically adjust the columns width to the maximum column it contains?

How can I MANUALLY set the column width of a column width header “mycolumn123” in the result table to 20 chars?

Welcome back to the forum. :wave:t3: Long time no see. :slightly_smiling_face:

There is no general setting telling PowerShell to adjust the output of all cmdlets to the way you prefer. But there’s an easy workaround. You can pipe the output to “Format-Table -AutoSize” to make that happen. If it’s just for console output you could use the shorter version and pipe it to “ft -a

Get-PnpDevice | Where-Object -Property Name -Match -Value Mass | Format-Table -AutoSize

… or - as mentioned - the shorter version …

Get-PnpDevice -FriendlyName *Mass* | ft -a