I am trying to get the last reboot time of some PCs from a list. When I use
foreach ($pc in $pclist) {
Get-CimInstance -ClassName win32_operatingsystem -C
If you want trim data past a certain length and manually specify column widths, you can pass a Width property for each property attribute.
For example, if you wanted your data to look like this:
Column 1 Column 2 Column 3 Column 4
-------- -------- -------- --------
Data Lorem ip... Lorem ip... Important data
Here's the basic Format-Table syntax, with a list of explicit properties:
$data | Format-Table -Property Col1, Col2, Col3, Col4 -AutoSize
Instead of just passing in the property names, we can add some additional metadata to Property:
$a = @{Expression={$_.Col1}; Label="Column 1"; Width=30},
@{Expression={$_.Col2}; Label="Column 2"; Width=30},
@{Expression={$_.Col3}; Label="Column 3"; Width=30},
@{Expression={$_.Col4}; Label="Column 4"; Width=30}
$data | Format-Table -Property $a
Note: I realize this is covered at the bottom of mklement0's more complete answer, but if this is your use case and you're scrolling quickly, I hope this helps highlight this strategy at a high level