Use Write-Output. (Almost all the time.)
(You can probably stop reading now if you like.)
Generally, use Write-Host if you want to make the text a funny colour etc – but that’s not always supported anyway.
If you want to read more and learn about various edge cases etc, cool. Lot’s of people have written much longer blog posts on the topic:
- StackOverflow
- ITPro Today
- DotNet-Helpers
- SQLJana
- PowerShell.org
- SQLServerBase.com
- 16 minute video by Shane Young
(But we both know you only came here for the first line of this blog post.)
Finally, it’s probably responsible to acknowledge that this blog post is deliberately a bit over simplistic. If you would like to read an articulate counter argument, you should check out:
- Puppycide done right: Output vs Messages (Thank you to Friedrich Weinmann for calling me out on not providing enough context.)
Happy coding!
1 comment for “PowerShell: Write-Host or Write-Output?”