PowerShell difference between Write-Host and Write-Output?

Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

PowerShell difference between Write-Host and Write-Output?

Message par Clippy »

PowerShell difference between Write-Host and Write-Output?
Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

Re: PowerShell difference between Write-Host and Write-Output?

Message par Clippy »

In a nutshell, `Write-Host` writes to the console itself. Think of it as a MsgBox in [VBScript](http://en.wikipedia.org/wiki/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

```
Répondre

Revenir à « PowerShell »