In today’s tutorial, I will explain how to create a table with headers in PowerShell. As a PowerShell expert, you should know this. Let me show you different methods to show this with examples.
To create a table with headers in PowerShell using the Format-Table cmdlet, you can pipe the output of a command into Format-Table and specify the properties you want as columns. For example, running Get-Process | Format-Table -Property Name, Id, CPU will display a table with headers “Name,” “Id,” and “CPU,” listing the corresponding details of running processes.
Create a Table with Headers in PowerShell
Tables allow you to format output in a structured way, making it easier to read and understand. This is particularly useful when dealing with large data sets or when you need to present information clearly and concisely.
PowerShell provides different methods for creating tables with headers. Let me show you each method with examples.
Method 1: Using Format-Table
The Format-Table cmdlet is mostly used to create a table with headers in PowerShell. It formats the output of a command as a table with the selected properties of the object in each column.
Syntax:
Here is the syntax:
Get-Process | Format-Table -Property Name, Id, CPUExample:
Let me show you an example.
Let’s say you want to list the running processes on your computer with their names, IDs, and CPU usage:
Get-Process | Format-Table -Property Name, Id, CPUThis command will output a table with headers: Name, Id, and CPU.
Here is the exact output in the screenshot below:

Check out PowerShell Format-Table Column Width
Method 2: Using Custom Objects
Creating custom objects in PowerShell allows for more flexibility and control over the data you display. This method is particularly useful when creating a table from scratch or combining data from different sources.
Syntax
Here is the syntax:
$Table = @()
$Table += [PSCustomObject]@{Name="John Doe"; Age=30; City="New York"}
$Table += [PSCustomObject]@{Name="Jane Smith"; Age=25; City="Los Angeles"}
$Table | Format-Table -AutoSizeExample
Now, let me show you an example.
Here’s how you can create a table with custom headers for a list of people:
$people = @()
$people += [PSCustomObject]@{Name="John Doe"; Age=30; City="New York"}
$people += [PSCustomObject]@{Name="Jane Smith"; Age=25; City="Los Angeles"}
$people += [PSCustomObject]@{Name="Michael Johnson"; Age=40; City="Chicago"}
$people | Format-Table -AutoSizeThis will output a table with headers: Name, Age, and City, showing the data for each person.
I executed the above PowerShell script using VS code, and you can see the exact output in the screenshot below:

Check out PowerShell Format-Table
Method 3: Using Out-GridView
Out-GridView is a cmdlet that sends output to an interactive table in a separate window. This is useful for larger datasets where scrolling and sorting might be necessary. This is another way to create a table with headers in PowerShell.
Syntax
Here is the syntax:
Get-Service | Out-GridViewExample
Here is an example.
To display a list of services on your computer in an interactive table:
Get-Service | Out-GridViewThis command will open a new window with a table that includes headers for the service properties.
Check out Create an HTML Table from Variables in PowerShell
Method 4: Creating Tables in Word Documents
Sometimes, you might need to export your table data to a Word document. PowerShell can automate this process, making it easy to create formatted documents.
Syntax
Here is the syntax:
$word = New-Object -ComObject Word.Application
$word.Visible = $true
$doc = $word.Documents.Add()
$table = $doc.Tables.Add($doc.Range(), 3, 3)
$table.Cell(1,1).Range.Text = "Name"
$table.Cell(1,2).Range.Text = "Age"
$table.Cell(1,3).Range.Text = "City"Example
Let me show you an example.
Here’s the complete PowerShell script to create a table in a Word document with headers:
$word = New-Object -ComObject Word.Application
$word.Visible = $true
$doc = $word.Documents.Add()
$table = $doc.Tables.Add($doc.Range(), 4, 3)
# Adding headers
$table.Cell(1,1).Range.Text = "Name"
$table.Cell(1,2).Range.Text = "Age"
$table.Cell(1,3).Range.Text = "City"
# Adding data
$table.Cell(2,1).Range.Text = "John Doe"
$table.Cell(2,2).Range.Text = "30"
$table.Cell(2,3).Range.Text = "New York"
$table.Cell(3,1).Range.Text = "Jane Smith"
$table.Cell(3,2).Range.Text = "25"
$table.Cell(3,3).Range.Text = "Los Angeles"
$table.Cell(4,1).Range.Text = "Michael Johnson"
$table.Cell(4,2).Range.Text = "40"
$table.Cell(4,3).Range.Text = "Chicago"You can see the exact output like in the screenshot below;

Conclusion
In this tutorial, I explained different methods to create a table with headers in PowerShell, such as using Format-Table for quick formatting, custom objects for more control, Out-GridView for interactive tables, or exporting to Word documents, etc.
I tried all these methods and got the exact required output. Do let me know if you still have any questions.
You may also like:
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.