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 -ComputerName $pc |
    select csname, lastbootuptime 
}

The output comes as following.

<pre>csname lastbootuptime ------ -------------- CONFA7-L1-1A 7/15/2016 9:55:16 AM CONFA7-L1-1F 5/31/2016 8:51:46 AM CONFA7-L1-1G 6/18/2016 11:09:15 AM CONFA7-L1... 6/26/2016 5:31:31 PM CONFA7-L3... 7/24/2016 3:48:43 PM</pre>

Which is neat, but if the PC name is long, I am unable to see the full name. So I pipelined Format-Table:

Get-CimInstance -ClassName win32_operatingsystem -ComputerName $pc |
  select csname, lastbootuptime |
  Format-Table  -HideTableHeaders 

And this is what I get:

<pre>CONFA7-L1-1A 7/15/2016 9:55:16 AM CONFA7-L1-1E 7/21/2016 12:58:16 PM CONFA7-L1-1F 5/31/2016 8:51:46 AM</pre>

There are two problems here.

  1. There is no heading. If I remove -HideTableHeaders there will be heading for every output which is not required.

  2. There is a lot of white spaces in between.

Basically I just need to get an output similar to the first one, but without truncating the full names. How can I fix these?

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:

<!-- language: lang-none -->
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:

<!-- language: lang-cs -->
$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