[2023 Update]
I’ve been meaning to update this for a while. The advice in this post is no longer current. A while ago we changed the implementation of Write-Host to being a wrapper on top of Write-Information. Prior to this, when you used Write-Host, there was no way to capture and process the data you wrote – because it just wrote to the host. Now that it uses Write-Information, it goes through a path that writes to the host AND allows you to capture and process that information.
-Jeffrey Snover
[End 2023 Update]
When you are writing or reviewing PowerShell scripts, I’d like you to remember the following rule of thumb:
- Using Write-Host is almost always wrong.