PowerShell Select-Object Without Header

As a PowerShell developer, I often need to format output in a specific way. One common requirement is using the Select-Object cmdlet without including the header in the output. If you’re working on a script that outputs data to a file or console, you might want to remove these headers. In this tutorial, I will explain everything about PowerShell Select-Object without header with examples.

PowerShell Select-Object

The Select-Object cmdlet in PowerShell is used to select specific properties of an object or set of objects. It includes headers in the output by default, which can sometimes clutter your data presentation.

Basic Usage of Select-Object

Let’s start with a basic example. Suppose we have a list of employees, and we want to select their first names and job titles:

$employees = @(
    [PSCustomObject]@{FirstName='John'; LastName='Doe'; JobTitle='Manager'},
    [PSCustomObject]@{FirstName='Jane'; LastName='Smith'; JobTitle='Developer'},
    [PSCustomObject]@{FirstName='Michael'; LastName='Johnson'; JobTitle='Analyst'}
)

$employees | Select-Object FirstName, JobTitle

This will output:

FirstName JobTitle
--------- --------
John      Manager
Jane      Developer
Michael   Analyst

You can even see the exact output in the screenshot below:

powershell select-object without header

Check out PowerShell Copy-Item

PowerShell Select-Object Without Header

To remove the headers from the output, we can use the Format-Table cmdlet with the -HideTableHeaders parameter. This is particularly useful when you need a clean output without any headers.

Example: Removing Headers

Continuing with our employee example, here’s how you can remove the headers:

$employees = @(
    [PSCustomObject]@{FirstName='John'; LastName='Doe'; JobTitle='Manager'},
    [PSCustomObject]@{FirstName='Jane'; LastName='Smith'; JobTitle='Developer'},
    [PSCustomObject]@{FirstName='Michael'; LastName='Johnson'; JobTitle='Analyst'}
)

$employees | Select-Object FirstName, JobTitle | Format-Table -HideTableHeaders

This will output:

John      Manager
Jane      Developer
Michael   Analyst

By using Format-Table -HideTableHeaders, we can achieve a cleaner look for our data.

Here is the exact output in the screenshot below:

powershell select-object no header

Check out PowerShell Write-Output

Export Data Without Headers

If you need to export your data to a file without headers, you can use the Export-Csv cmdlet with the -NoTypeInformation and -Encoding parameters. However, since Export-Csv doesn’t have a built-in way to remove headers, we need to get a bit creative.

Let me show you an example.

Example: Exporting to CSV

Here’s a way to export data to a CSV file without headers:

$employees = @(
    [PSCustomObject]@{FirstName='John'; LastName='Doe'; JobTitle='Manager'},
    [PSCustomObject]@{FirstName='Jane'; LastName='Smith'; JobTitle='Developer'},
    [PSCustomObject]@{FirstName='Michael'; LastName='Johnson'; JobTitle='Analyst'}
)

$employees | Select-Object FirstName, JobTitle | Export-Csv -Path "C:\MyFolder\employees.csv" -NoTypeInformation -Encoding UTF8

# Remove the first line (header) from the CSV
(Get-Content -Path "C:\MyFolder\employees.csv" | Select-Object -Skip 1) | Set-Content -Path "C:\MyFolder\employees_no_header.csv"

This script first exports the data to a CSV file and then removes the first line, which contains the headers, by using Select-Object -Skip 1.

Conclusion

In this tutorial, I explained how to remove headers from PowerShell output while working with Select-Object using Format-Table. Do let me know in the comments below if it helps.

You may also like:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.