# PowerShell – Working with Format-Table in Verbose, Debug, Output Streams

As you may know, PowerShell has multiple streams. Write-Output, Write-Error, Write-Warning, Write-Verbose, Write-Debug, and Write-Information. It also has Write-Host which until PowerShell 5 was a bit special. Since PowerShell 5.1 it’s a wrapper over Write-Information, so it doesn’t kill puppies anymore. While I could spend the next five pages trying to give my best and describe those streams, there are already many articles describing them in detail. Please check the following link if you need that information.

blog

18 Nov 2018 de

![PowerShell – Working with Format-Table in Verbose, Debug, Output Streams](/wp-content/uploads/2018/11/img_5bf1c141c75ec.png)

[Bilder ansehen (9)](#pf-content-image-1-0)

As you may know, **PowerShell **has multiple streams. You can use those streams using following functions **Write-Output**, **Write-Error**, **Write-Warning**, **Write-Verbose**, **Write-Debug**, and **Write-Information**. It also has **Write-Host** which until PowerShell 5 was a bit **special**. Since PowerShell 5.1 it's a wrapper over **Write-Information, **so it doesn't kill puppies anymore and it's safe to use. While I could spend the next five pages trying to give my best and describe those streams, there are already many articles describing them in detail. Please check the following link if you need that information.

- 📝 [Weekend Scripter: Welcome to the PowerShell Information Stream](https://blogs.technet.microsoft.com/heyscriptingguy/2015/07/04/weekend-scripter-welcome-to-the-powershell-information-stream/)

Before you read about **Format-Stream** you may also be interested in [**PSWriteColor **](https://evotec.xyz/hub/scripts/pswritecolor/)which provides excellent options for working with **colors** using **Write-Host**. But let's not get too distracted. As you may even know there are nice commands that can help you output your **HashTables**, **OrderedDictionary**, **PSCustomObjects,** and many custom ones to a beautiful looking **Table** or a **List**. Those are **Format-Table** and **Format-List**.

[!\[Format-Table / Format-List\](/wp-content/uploads/2018/11/img_5bf1b58be688d.png)](/wp-content/uploads/2018/11/img_5bf1b58be688d.png)

The output from those commands is nice and really useful. But what if you want to use those commands in other streams? Such as Debug? Verbose? Or if you want to send that output to file?

```powershell
PS C:\Users\pklys> Get-Process | Select-Object -First 5 |Format-List | Add-Content -Path 'C:\testor.txt'
PS C:\Users\pklys> Get-Process | Select-Object -First 5 |Format-Table | Add-Content -Path 'C:\testor.txt'
```

You would get something like this

```powershell
Microsoft.PowerShell.Commands.Internal.Format.FormatStartData
Microsoft.PowerShell.Commands.Internal.Format.GroupStartData
Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
Microsoft.PowerShell.Commands.Internal.Format.GroupEndData
Microsoft.PowerShell.Commands.Internal.Format.FormatEndData
Microsoft.PowerShell.Commands.Internal.Format.FormatStartData
Microsoft.PowerShell.Commands.Internal.Format.GroupStartData
Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
Microsoft.PowerShell.Commands.Internal.Format.GroupEndData
Microsoft.PowerShell.Commands.Internal.Format.FormatEndData
Microsoft.PowerShell.Commands.Internal.Format.FormatStartData
Microsoft.PowerShell.Commands.Internal.Format.GroupStartData
Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
Microsoft.PowerShell.Commands.Internal.Format.GroupEndData
Microsoft.PowerShell.Commands.Internal.Format.FormatEndData
```

And in **Debug**/**Verbose **streams it's not available at all. Not useful right? So I've searched for a solution but couldn't find anything that would be enough for me to use. I always had some problems with them. And both **Format-Table** and **Format-List** have their benefits. That's where my **Format-Stream** function comes in that I've written over the weekend.

### 💡 Format-Stream – What's that?

**Format-Streams** is supposed to fill the gap and allow you to work with **Format-Table** / **Format-List** in Verbose, Debug, Output, Informational and “Host” streams. It's also cross-platform working on **Windows**, **Linux**, and **Mac**. It's part of **[PSSharedGoods](https://evotec.xyz/hub/scripts/pssharedgoods-powershell-module/) **module even thou it could probably do on its own. But since I've recently fixed it's[load time from, 12 seconds to 200 milliseconds,](https://evotec.xyz/powershell-single-psm1-file-versus-multi-file-modules/) it's staying as part of **PSSharedGoods** module. Which isn't that bad since if you're using any of my other modules such as **PSWriteWord**, **PSWriteExcel**, **PSAutomator**, **PSWinReporting** you already have it. You just need to update it.

### 💡 Format-Stream – Verbose

As it stands **Format-Stream,** by default, outputs **Table **or** List** in Verbose mode. Its usage is quite simple, and you mainly use it like you would use Format-Table or Format-List.

```powershell
Get-Process | Format-Stream
```

[!\[Format-Stream used as Verbose\](/wp-content/uploads/2018/11/img_5bf1bdd634d7a.png)](/wp-content/uploads/2018/11/img_5bf1bdd634d7a.png)

```powershell
Get-Process | Select-Object -First 1 | Format-Stream -List
```

[!\[Format-Stream -List\](/wp-content/uploads/2018/11/img_5bf1bedf301ce.png)](/wp-content/uploads/2018/11/img_5bf1bedf301ce.png)

### 💡 Format-Stream – Debug

```powershell
Get-Process | Select-Object -First 5 | Format-Stream Name, PriorityClass, HandleCount -Stream Debug -List
Get-Process | Select-Object -First 5 | Format-Stream Name, PriorityClass, HandleCount -Stream Debug
```

As you can see above **Format-Stream** displays just fine in **DEBUG** stream in both **Table** and **List** modes. If you will give a wildcard or won't define properties at all **Format-Stream** will try to fill in the maximum size of the screen. You can also define additional parameters such as **ExcludeProperty**, **AlightRight **or **HideTableHeaders**.

[!\[Format-Stream - Debug\](/wp-content/uploads/2018/11/img_5bf1c141c75ec.png)](/wp-content/uploads/2018/11/img_5bf1c141c75ec.png)

```powershell
Get-Process | Select-Object -First 5 | Format-Stream * -Stream Debug
Get-Process | Select-Object -First 5 | Format-Stream -Stream Debug
Get-Process | Select-Object -First 5 | Format-Stream -Stream Debug -ExcludeProperty Name, SI, Handles -AlignRight -HideTableHeaders
```

### 💡 Format-Stream – Output

Like you've probably already noticed each output type behaves similar and works with same parameter sets. There are also **Transpose** and **TransposeSort** parameters which allows you to convert **PSCustomObject** to **HashTable** and vice versa.

```powershell
Get-Process | Select-Object -First 5 | Format-Stream * -Stream Output
Get-Process | Select-Object -First 5 | Format-Stream Name,ID -Stream Output -Transpose
Get-Process | Select-Object -First 5 | Format-Stream Name,ID -Stream Output -List
```

[!\[Format-Stream output examples showing process data rendered through the PowerShell Output stream.\](/wp-content/uploads/2018/11/img_5bf1c21cdf8ec.png)](/wp-content/uploads/2018/11/img_5bf1c21cdf8ec.png)

There's one more trick to Output stream. You can output it to file. And it will keep its form.

```powershell
Get-Process | Select-Object -First 5 | Format-Stream * -Stream Output | Add-Content -Path 'C:\test.txt'
Get-Process | Select-Object -First 5 | Format-Stream Name,ID -Stream Output -Transpose | Add-Content -Path 'C:\test.txt'
Get-Process | Select-Object -First 5 | Format-Stream Name,ID -Stream Output -List | Add-Content -Path 'C:\test.txt'
```

[!\[Format-Streams - Output to File\](/wp-content/uploads/2018/11/img_5bf1c430615db.png)](/wp-content/uploads/2018/11/img_5bf1c430615db.png)

### 💡 Format-Streams – Informational and Host output

You can do an exactly the same thing with the **Informational** stream like with others if you need to. So I won't bother you with showing how and providing a screenshot. Finally, I wanted to show what **Host** is able to do. Apart from standard functionality that all other streams there's one little, maybe not very configurable feature.

[!\[Format-Stream Colors\](/wp-content/uploads/2018/11/img_5bf1c6c418843.png)](/wp-content/uploads/2018/11/img_5bf1c6c418843.png)

```powershell
Get-Process | Select-Object -First 5 | Format-Stream * -Stream Host -ForegroundColor Green,Red, Yellow -ForegroundColorRow 2,4,5
Get-Process | Select-Object -First 5 | Format-Stream Name,ID -Stream Host -ForegroundColor Green,Red, Yellow -ForegroundColorRow 2,4,5
Get-Process | Select-Object -First 5 | Format-Stream Name,ID -Stream Host -List
```

[!\[Format-Streams Color on Linux\](/wp-content/uploads/2018/11/img_5bf1c89f7d2a5.png)](/wp-content/uploads/2018/11/img_5bf1c89f7d2a5.png)

See what I did there? And it's cross-platform for all streams as well. Hope you like it. If there's already something similar on Google I wasn't able to found it. But it was fun to make it work. Enjoy.

### 💡 Required prerequisites

Before you can use this script, you need to do a few manual steps. Since this script is published as a module, it's quite easy to set this up. Just execute the command below (accept warnings) .. and you can test it out.

```powershell
Install-Module PSSharedGoods

#Update-Module PSSharedGoods
```

You can of course install everything manually from **GitHub** (as everything is published there) but it will be far easier to just use **Install-Module**.

### 💡 Alternative method

There also seems a way to do it without Write-Stream using some neat trick with Out-String. Choose your own poison.

```powershell
Get-Process | Sort-Object WS -Descending | Select-Object -First 10 | Format-Table  | Out-String | Write-Verbose
Get-Process | Sort-Object WS -Descending | Select-Object -First 10 | Format-Table  | Out-String | Write-Debug
Get-Process | Sort-Object WS -Descending | Select-Object -First 10 | Format-Table  | Out-String | Write-Output
Get-Process | Sort-Object WS -Descending | Select-Object -First 10 | Format-Table  | Out-String | Write-Host
```

[!\[Alternative Out-String approach writing formatted table output into verbose, debug, output, and host streams.\](/wp-content/uploads/2018/11/img_5bf1f0cc99d6f.png)](/wp-content/uploads/2018/11/img_5bf1f0cc99d6f.png)

Keep in mind that you won't see Debug or Verbose without explicitly asking for it.

## Zugehörige Projekte

Projekte, die zu Tags, Kategorien und Inhalt dieses Beitrags passen.

[Alle Projekte](/de/projekte/)

Projekte werden abgeglichen...

[Zurück zum Blog](/blog)

## Ähnliche Beiträge

- [PowerShell – How to format Write-Host with multiple colors](/de/blog/powershell-how-to-format-powershell-write-host-with-multiple-colors/)
- [Check an API write after a PowerShell timeout](/de/blog/verify-uncertain-api-outcomes-powershell/)
- [Compose PDF reports and automate page workflows with PSWriteOffice](/de/blog/automate-pdf-reports-and-page-workflows-pswriteoffice/)

<!-- PowerForge markdown artifact sha256:6B34D3A2FE0EB7C9A0B668F97D540320C3E8FACEBBA4BA48BAC7A698DC49DF38 -->
