Windows – PowerShell difference between Write-Host and Write-Output

powershellwindows

What is the difference between Write-Host and Write-Output in PowerShell?

Like…

Write-Host "Hello World ";

Write-Output "Hello World";

Best Answer

In a nutshell, Write-Host writes to the console itself. Think of it as a MsgBox in VBScript. Write-Output, on the other hand, writes to the pipeline, so the next command can accept it as its input. You are not required to use Write-Output in order to write objects, as Write-Output is implicitly called for you.

PS> Get-Service

would be the same as:

PS> Get-Service | Write-Output