Powershell Best Practice #3: Avoid Write-Host

By | May 22, 2015

Best Practice: It is recommended to avoid Write-Host (unless your goal is to write to the host only).


Write-Host is like a picture sent to the screen, it sends to the host and does not return any objects, it is not possible to export or convert in a specific format. Write-Host has too many limitations.

In some rare cases, you could use Write-Host if you want to display text in a specific color (ForegroundColor) or with specific background (BackgroundColor) only on the screen (ex: display in color some specific lines of a log, etc.).

But anyway, Write-Host is not needed most of the time.

Here are few alternatives to Write-Host:

  • Verbose messages: Write-Verbose
  • Warning messages: Write-Warning
  • Error messages: Write-Error
  • Debug messages: Write-Debug


Leave a Reply

Your email address will not be published.