Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell: Format-Table without headers

Tags:

In a PowerShell script, I have some objects that I pass to the Format-Table CmdLet.
The output of my script looks like this:

Something...  Operation AttributeName  AttributeValue --------- -------------  -------------- Delete    Member         John Doe  Something else... 

Since the meaning of the fields is pretty self-explanatory, I would like to remove the headers, the '---' separators and the blank lines at the beginning and at the end from the output of Format-Table.
I don't think that the CmdLet supports this (or at least if there's a parameter to do this I couldn't find it).

What would the best way to leave only the lines with the actual values from the output of Format-Table?

like image 802
Paolo Tedesco Avatar asked Jul 15 '10 11:07

Paolo Tedesco


People also ask

How do I display output in a Table Format in PowerShell?

The Format-Table cmdlet formats the output of a command as a table with the selected properties of the object in each column. The object type determines the default layout and properties that are displayed in each column. You can use the Property parameter to select the properties that you want to display.

What is FT in PowerShell?

Windows PowerShell Scripting – Format-Table (FT) Format-Table, or FT for short, controls the formatting of the output of your Windows PowerShell commands. Whenever presentation of information is important, pipe the script's output into Format-Table.

What is the difference between Format-list and Format wide cmdlets?

Each cmdlet also uses the same Property parameter to specify which properties you want to display. Because Format-Wide only shows a single property, its Property parameter only takes a single value, but the property parameters of Format-List and Format-Table accept a list of property names.

What does Fl mean in PowerShell?

Windows PowerShell Scripting – Format-List (fl) Format-List, or FL for short, allows PowerShell to control the output of your main script. Whenever presentation of information is important, pipe the script's output into Format-List (or Format-Table).


2 Answers

Try the -HideTableHeaders parameter to Format-Table:

gci | ft -HideTableHeaders 

(I'm using PowerShell v2. I don't know if this was in v1.)

like image 189
Jay Bazuzi Avatar answered Sep 19 '22 12:09

Jay Bazuzi


Try -ExpandProperty. For example, I use this for sending the clean variable to Out-Gridview -PassThru , otherwise the variable has the header info stored. Note that these aren't great if you want to return more than one property.

An example:

Get-ADUser -filter * | select name -expandproperty name 

Alternatively, you could do this:

(Get-ADUser -filter * ).name 
like image 36
KERR Avatar answered Sep 19 '22 12:09

KERR