﻿# Does having Format-Table or Format-List in the middle of the pipeline makes sense? | Evotec Blog

blog

# Does having Format-Table or Format-List in the middle of the pipeline makes sense?

24 Apr 2019en

![Does having Format-Table or Format-List in the middle of the pipeline makes sense?](/wp-content/uploads/2019/04/img_5cc0b9be73559.png)

Path

1. [Home](/)
2. [Blog](/blog/)
3. Does having Format-Table or Format-List in the middle of the pipeline makes sense?

Explore this stream

[Back to Blog](/blog/)[All categories](/categories/)[All tags](/tags/)

**Categories**

[PowerShell](/blog/?category=PowerShell)

**Tags**

[Format-List](/blog/?tag=Format-List)[Format-Table](/blog/?tag=Format-Table)[powershell](/blog/?tag=powershell)

**Browse**

[All categories](/categories/)[All tags](/tags/)

[View images (5)](#pf-content-image-1-0)

Recently there was this discussion on **PowerShell Group on Facebook** about issue posted by one user. While the subject doesn't matter for this post, few people commented on the idea that he was using **Format-Table** in the middle of the pipeline to do something. They all said **Format-Table** should be used as last in the pipeline. Otherwise, you would get the wrong output. But should it? Well, it depends!

### 💡 Use case for Format-Table / Format-List

Your standard use case for Format-Table or Format-List would be something like this

```
Get-Process | Format-Table -Autosize
```

[!\[PowerShell console showing Get-Process formatted as a table\](/wp-content/uploads/2019/04/img_5cc0b9be73559.png)](/wp-content/uploads/2019/04/img_5cc0b9be73559.png)

But what if you would like to have that data **exported to file?** Well, it depends. If you want further use the data in a way that can be imported back to **PowerShell**, to **Excel**, or have some kind of easy processing later on you should use proper commands.

```
# Exports to XML
Get-Process | Export-CliXml -LiteralPath $Env:USERPROFILE\Desktop\MyFile.xml
# Exports to CSV
Get-Process | Export-Csv -LiteralPath $Env:USERPROFILE\Desktop\MyCsv.csv
# Export to Excel (using PSWriteExcel module)
Get-Process | ConvertTo-Excel -FilePath $env:USERPROFILE\Desktop\MyExcel.xlsx -WorksheetName 'MyName'
# Export to HTML (using PSWriteHTML module)
Get-Process | Out-HtmlView
```

And all those commands will give you file output that will be in a form that you can do something with it.

### 💡 Format-Table / Format-List in the middle of the pipeline?

But if you wanted to use **Format-Table** and have that output in a file? While it may not be obvious, it does work.

```
Get-Process | Format-Table -AutoSize | Add-Content -LiteralPath $Env:USERPROFILE\Desktop\MyOtherOutput.txt
```

[!\[Text file output produced by piping Format-Table into Add-Content\](/wp-content/uploads/2019/04/img_5cc0bce948305.png)](/wp-content/uploads/2019/04/img_5cc0bce948305.png)

```
Get-Process | Format-Table -AutoSize | Set-Content -LiteralPath $Env:USERPROFILE\Desktop\MyOtherOutput1.txt
```

[!\[Text file output produced by piping Format-Table into Set-Content\](/wp-content/uploads/2019/04/img_5cc0bcd1e7fb6.png)](/wp-content/uploads/2019/04/img_5cc0bcd1e7fb6.png)

Ok, so it's not what we expected right? And that's why people are saying to use **Format-Table**, **Format-List** as last in the pipeline because it's supposed to be for display purposes only. How about this?

```
Get-Process | Format-Table -AutoSize | Out-File -LiteralPath $Env:USERPROFILE\Desktop\MyOutput.txt
```

[!\[Formatted process table preserved when piping Format-Table into Out-File\](/wp-content/uploads/2019/04/img_5cc0bd48a9b4d.png)](/wp-content/uploads/2019/04/img_5cc0bd48a9b4d.png)

So, it seems Out-File is able to deliver what you see on the screen into a file! But that's not all. What if we wanted to use **Set-Content** and **Add-Content** the same way we use **Out-File**? Take a look at this

```
# See output
Get-Process | Format-Table -AutoSize | Out-String

# Export to file
Get-Process | Format-Table -AutoSize | Out-String | Set-Content -LiteralPath $Env:USERPROFILE\Desktop\MyOtherOutput1.txt
```

[!\[Formatted process table preserved after Out-String and Set-Content\](/wp-content/uploads/2019/04/img_5cc0bd7d68bbc.png)](/wp-content/uploads/2019/04/img_5cc0bd7d68bbc.png)

See, we merely introduced **Out-String** which gives me the same output as you would get with **Out-File**. So, can we use **Format-Table/Format-List** in the middle of the pipeline? Yes, we can! But the output will not be an object that we can quickly process later on. Still, if we just wanted to see the same thing we have on screen in the form of a file, why not use it that way? There are a couple of other ways to use **Out-String** and **Format-Table**, but that's something for another blog post.

## Related Projects

Projects that align with this post's tags, categories, and content.

[All projects](/projects/)

Matching projects...

[Back to Blog](/blog)

[Newer post: The only PowerShell Command you will ever need to find out who did what in Active Directory](/blog/the-only-powershell-command-you-will-ever-need-to-find-out-who-did-what-in-active-directory/)[Older post: The curious case of $null should be on the left side of equality comparisons PSScriptAnalyzer](/blog/the-curious-case-of-null-should-be-on-the-left-side-of-equality-comparisons-psscriptanalyzer/)

## Related posts

- [Compose PDF reports and automate page workflows with PSWriteOffice](/blog/automate-pdf-reports-and-page-workflows-pswriteoffice/)
- [ImagePlayground: image automation that stays in PowerShell](/blog/imageplayground-powershell-image-automation/)
- [PowerBGInfo 2.x: support-ready Windows backgrounds from PowerShell](/blog/powerbginfo-support-ready-windows-backgrounds/)
