Writing Output from Powershell

One of the things we often want to do when building a PoSh script is to get some output. I first learned about Write-Host, but I learned over time that this isn’t the best way to do this. Most of the early scripts I saw used this, so I was confused until I went through a few of this post: Write-Host Considered Harmful. This is from Jeffrey Snover, the inventor of PoSh.

In the post, he notes that most of the time we don’t want to use Write-Host, because this means we can’t use the output of a command in the pipeline. For debugging you might think that this doesn’t matter, but Write-Debug is better.

He recommend Write-Output, which is something I want to start to use. That, or Write-Verbose, so the user can get more or less output as needed.

Hopefully this will help me to better write PoSh code that others can easily use.

About way0utwest

Editor, SQLServerCentral
This entry was posted in Blog and tagged , . Bookmark the permalink.

2 Responses to Writing Output from Powershell

  1. Greg Moore says:

    Excellent to know. I’ll be right (write?) back. I’ve got more than a few scripts to update!


  2. way0utwest says:

    Me too! Working on writing about write-debug as well


Comments are closed.