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?
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.
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.
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.
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).
Try the -HideTableHeaders
parameter to Format-Table
:
gci | ft -HideTableHeaders
(I'm using PowerShell v2. I don't know if this was in v1.)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With