Powershell Best Practice #3: Avoid Write-Host

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

PowerShell

1

Write-Host-Object'Successfully completed'

Explanation:

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.).

It can be handy for feedback. For example if you want to show the progress when running a long script.
I finished a script today that shows live patch information and this script collects data from all servers. This can take up to 15 minutes and with write-host I show the user running the script how much % the script is done.